Console Learner — An interactive JavaScript course.


1.4 Type Coercion & Equality

All equality operators are based on the Object.equals method. There is no identity operator or pointer comparison available.
Type coercion means to force (convert) a value from one type to another.
>>>
"text" == 'text'
true
>>>
"text" == "another text"
false
>>>
1 == "1"
true
Type coercion in effect. The string value is converted to a number before the comparison.
>>>
1 === "1"
false
>>>
null == undefined
true
Unexpected but nonetheless convenient. Using type coercion, a test for null will also match undefined values.
>>>
"" + 13
"13"
Type coercion can be forced explicitly. For example, a string result is forced by concatenating with an empty string. Note that the + operator has multiple meanings (more later).
>>>
String(true)
"true"
Remember those wrapper classes for the primitive types? These can be called as normal functions for type coercion to the corresponding primitive type.
>>>

The console allows you to interact with the course material and examples. Use the following keys:

A special logging function is also available:


Need more magic? Check out the other developer tools on this site.