<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/javascript/tags/easy</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Tue, 02 Dec 2008 02:55:39 GMT</pubDate>
<item>
<title>(JavaScript) Conditionally assign a value to a variable - noah</title>
<link>http://snipplr.com/view/6850/conditionally-assign-a-value-to-a-variable/</link>
<description><![CDATA[ <p>To assign a value to a variable only if some expression evaluates to true, I would usually do this:

var foo;
if (condition){
    foo = "success";
}


This is Douglas Crockford's idiom and it shortens the above from 4 lines to 1.

I have understood for a while that (expr1 &amp;&amp; expr2) evaluates to truth only if both conditions are true.  What I did not get before Crockford pointed it out in his book, was that &amp;&amp; doesn't simply return a boolean value -- it returns the result of the last expression that was evaluated.

So if both expressions evaluate to false, the result of first expression will be returned.  If only one expression evaluates true, the result of the false expression will be returned.  And if both expressions evaluate to truth, the result of the second expression is returned.</p> ]]></description>
<pubDate>Mon, 23 Jun 2008 08:44:59 GMT</pubDate>
<guid>http://snipplr.com/view/6850/conditionally-assign-a-value-to-a-variable/</guid>
</item>
<item>
<title>(JavaScript) List all IDs in the DOM tree - noah</title>
<link>http://snipplr.com/view/6487/list-all-ids-in-the-dom-tree/</link>
<description><![CDATA[ <p>List all the IDs on the page.</p> ]]></description>
<pubDate>Wed, 28 May 2008 17:27:18 GMT</pubDate>
<guid>http://snipplr.com/view/6487/list-all-ids-in-the-dom-tree/</guid>
</item>
<item>
<title>(JavaScript) Safely Get and Operate Upon An Element - noah</title>
<link>http://snipplr.com/view/3071/safely-get-and-operate-upon-an-element/</link>
<description><![CDATA[ <p>Pass this an ID or an object reference, as well as any number of functions that take the referenced object as a parameter.  This wrapper is intended to provide a sanity check against missing DOM elements.</p> ]]></description>
<pubDate>Thu, 28 Jun 2007 20:09:25 GMT</pubDate>
<guid>http://snipplr.com/view/3071/safely-get-and-operate-upon-an-element/</guid>
</item>
<item>
<title>(JavaScript) infinite loop alert - noah</title>
<link>http://snipplr.com/view/2848/infinite-loop-alert/</link>
<description><![CDATA[ <p>just some goofy code ^.^</p> ]]></description>
<pubDate>Tue, 12 Jun 2007 04:40:27 GMT</pubDate>
<guid>http://snipplr.com/view/2848/infinite-loop-alert/</guid>
</item>
<item>
<title>(JavaScript) Does an object have a specific property? - noah</title>
<link>http://snipplr.com/view/2708/does-an-object-have-a-specific-property/</link>
<description><![CDATA[ <p>This is a very easy way to check if an object has a given property.  Easier than checking if (obj.foo != null) or some such, which is what I've been doing :(  From Flanagan, 5th ed, p. 108.; but I actually ran across it in the source of this page: http://www.gtalbot.org/DHTMLSection/DynamicOpacity.html, thanks to Gerard Talbot on clj.</p> ]]></description>
<pubDate>Thu, 24 May 2007 09:24:08 GMT</pubDate>
<guid>http://snipplr.com/view/2708/does-an-object-have-a-specific-property/</guid>
</item>
<item>
<title>(JavaScript) Calculate net paycheck - noah</title>
<link>http://snipplr.com/view/2517/calculate-net-paycheck/</link>
<description><![CDATA[ <p>Given my base pay and an optional pre-tax 401k contribution percentage, calculate my net pay.  Assumes US income tax of 27%.  All results will be approximate (the browser is not a reliable calculator)!</p> ]]></description>
<pubDate>Mon, 23 Apr 2007 14:01:42 GMT</pubDate>
<guid>http://snipplr.com/view/2517/calculate-net-paycheck/</guid>
</item>
</channel>
</rss>