Checking the Data Type
We should learn (or re-learn) how to check the data type of a variable and the value contained within. Let’s bring up the Console first. You can do this in Chrome, Firefox and Safari by right-clicking on the page and choosing the ‘Inspect Element’ option:
This is what the Chrome ins
You have two ways to access the console, you can click on the tab located in the toolbar:
Or you can press the ESC key to bring it up in the Elements section.
Checking the Value
If we would like to check the value contained within a variable, then we can use the console.log() method to print to the console. You should
var hello = "Hello World"; console.log(hello); // output: "Hello World"
In the console:
Check the Data Type
If you would like to check for the data type that a variable belongs to, then you can use the typeof operator.
var hello = "Hello World"; console.log(typeof hello); //outputs "string"
Here are some examples of the code in the console.
Truthy vs. Falsy