Here are some interesting things:
- Comparing
NaN
with anything (even NaN
) is always false, that includes ==
, <
and >
.
NaN
Stands for Not a Number but if you ask for the type it actually returns a number.
Array.sort
can take a comparator function and is called by a quicksort-like driver (depends on implementation).
- Regular expression "constants" can maintain state, like the last thing they matched.
- Some versions of JavaScript allow you to access
$0
, $1
, $2
members on a regex.
null
is unlike anything else. It is neither an object, a boolean, a number, a string, nor undefined
. It's a bit like an "alternate" undefined
. (Note: typeof null == "object"
)
- In the outermost context,
this
yields the otherwise unnameable [Global] object.
- Declaring a variable with
var
, instead of just relying on automatic declaration of the variable gives the runtime a real chance of optimizing access to that variable
- The
with
construct will destroy such optimzations
- Variable names can contain Unicode characters.
- JavaScript regular expressions are not actually regular. They are based on Perl's regexs, and it is possible to construct expressions with lookaheads that take a very, very long time to evaluate.
- Blocks can be labeled and used as the targets of
break
. Loops can be labeled and used as the target of continue
.
- Arrays are not sparse. Setting the 1000th element of an otherwise empty array should fill it with
undefined
. (depends on implementation)
if (new Boolean(false)) {...}
will execute the {...}
block
- Javascript's regular expression engine's are implementation specific: e.g. it is possible to write "non-portable" regular expressions.
[updated a little in response to good comments; please see comments]