JavaScript distinguishes between values and objects

In Java Integer is an object and int is a primitive type (a plain value), that can be converted to the Integer object using Java's auto-boxing capability. JavaScript is similar: Executing the following in Chrome's Developer Tools JavaScript console, will show you the difference between an object and a number in JavaScript:


typeof 1
"number"
typeof new Number(1)
"object"
1 instanceof Number
false
new Number(1) instanceof Number
true
So you see that var myNum = 1; isn't the same as var myNum = Number(1);.

Comments

Popular posts from this blog

Tuning ext4 for performance with emphasis on SSD usage

NetBeans 6.1: Working with Google´s Android SDK, Groovy and Grails