Data Type Testing
Let’s learn about testing data types in JavaScript.
We'll cover the following
How is testing done?
To test the equality or inequality of two primitive data values, we always use the triple equality symbol (===
and !==
) instead of the double equality symbol (==
and !=
). Otherwise, for instance, the number 2
would be the same as the string "2"
since the condition 2 == "2"
evaluates to true
in JavaScript.
Assigning an empty array literal, as in var a = []
, is the same as invoking the Array()
constructor without arguments, as in var a = new Array()
. Assigning an empty object literal, as in var o = {}
, is the same as invoking the Object()
constructor without arguments, as in var o = new Object()
.
Notice, however, that an empty object literal {}
is not really an empty object, as it contains property slots and method slots inherited from Object.prototype
. So, a truly empty object (without any slots) has to be created with null
as the prototype, like in var emptyObject = Object.create(null)
.
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy