JavaScript: Difference between revisions

add more
No edit summary
add more
Line 1: Line 1:
=== examples ===
=== examples ===
things to watch out for in automatic type conversion.
<syntaxhighlight lang="javascript">
"Apollo" + 5; // Apollo5
null + "ify": // nullify
"5" * 5; // 25
"strawberry" * 5; // NaN
NaN == NaN; // false  use isNaN() function instead
</syntaxhighlight>
<syntaxhighlight lang="javascript">
</syntaxhighlight>
automatic type conversion. To disallow automatic type conversion, use === or !== operators.
<syntaxhighlight lang="javascript">
false == 0; // true
"" == 0; // true
"5" == 5; // true
</syntaxhighlight>
Check if something is null or defined.  if a variable has been defined ("var something") but it hasn't been assigned anything, it returns undefined. All of functions that have no return values also return undefined.
<syntaxhighlight lang="javascript">
if (something == undefined) // either undefined or null
</syntaxhighlight>


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">