-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
In Javascript the equal to operator, known as "==", can be used with mixed types.
The intern process for comparing mixed types of values is as follows:
Type | Process |
---|---|
null | None |
undefined | None |
string | Convert to number |
boolean | Convert to number |
number | Use number value |
Non-Date object | Try toString and then valueOf |
Date-object | Try toString and then valueOf |
string and boolean are converted to number before they are compared to each other. It is different with objects.
To understand the first two types and the last two in the table, two code examples will be shown:
1.
var dateObject = new Date("2017/12/31");
dateObject == "2017/12/31";//false
The reason why the result outputs false is that the value of the dateObject is actually "Sat May 13 2017 00:00:00 GMT+0200 (PST)". The argument in the Date object triggers a time stamp from that date.
2.
undefined == null;//true
The second example is always true and in this specific case a conversion is not needed.
The user interaction part should look like the content as seen below by starting "index.html" in a web browser.
With the drop down list in "Equal To" the User can choose which type of combination should be checked.
The colored areas are just for a better readability in the wiki and are not part of the content. To use the project just download the files and execute "index.html". Note that all files should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman