0

JavaScript is Strange

Reading Time: 1 minute

Some say JavaScript is a powerful scripting language and some other say it is a strange language and whoever is new to JavaScript just make a note of the things mentioned below. One more note is JavaScript is not a right choice for mathematical calculation based applications/operations and you will know why

0 == +0;//true
0 == -0;//true
+0 == -0;//true
-0 == -0;//true

"true" == 1;//false
"false" == 1;//false

true == 1;//true
false == 0;//true

0.1 + 0.2 == 0.3;//false
(0.1 + 0.2) == 0.3;//false 

0.1 + 0.2;//0.30000000000000004
//so now you know why JavaScript not good for calculations

typeof null;//object
null instanceof Object;//false
typeof NaN;//number
NaN == NaN;//false
typeof undefined;//undefined
undefined == undefined;//true

var test;
test == false;//false
test == true;//false
if(test) {alert('true');} else {alert('false');}//false
test;//undefined
new Array() == false;//true

var sumOfArray = []+[];
console.log(typeof(sumOfArray));//string

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.