Variable Hoisting in JavaScript

Will this program alert? Will something be logged to the console?

 alert(5); console.log'alerted';

We are obviously missing some parentheses around the argument passed to console.log but what will that cause the browser to do? This will result in a SyntaxError. Syntax errors do not make it past the interpreter and our program does not run. It is invalid JS and nothing is alerted.

Uncaught SyntaxError: Unexpected string 

What will happen here? Anything alerted or …

Read Article

Type Checking in JavaScript

At first, type checking may seem like a straightforward concept. A value can either be an object, a function, an array, a number, a string, a boolean, null, or undefined. JavaScript has the typeof operator which returns a string indicating the type of the operand.

typeof 5 === 'number' // true 

Easy as pie, right? Unfortunately, typeof is not as reliable as you might think.

What does the following equal?

typeof NaN 

If you …

Read Article