1. Always use === and !== instead of == and !=

alert('' == '0'); //false
alert(0 == ''); // true
alert(0 =='0'); // true

 

2.  Assigning default values to variables

You can use the logical or operator || in an assignment expression to provide a default value:

var i = x || y;

The i variable will get the value of y only if x is false (if is null, false, undefined, 0, empty string, or NaN), otherwise i will get the value of x.

3. True or False

if(x) and x=1, 1/2, 0.00001, 5.3, -1, "string" then condition is
always true.

typeof NaN === 'number' //true
if(x) and x=0, 0.0, null, undefined, "", NaN then condition is always false

NaN === NaN //false

 

4. String literals can be shown as follow

var string= "A quick brown \
fox jumps \
over the lazy dog";

 

5.  Check an object is empty by:

Object.keys(obj).length === 0

 

 

 

 

Advertisements