Hey everyone 👋🏻,
const a = 4; const b = 34.44;
Unlike other programming languages, here you don’t have to specifically declared for integer or floating values using int, float as we do in C++, Java etc. With the variables of this data type, you can perform operations like addition, subtraction, multiplication, exponentiation etc.
const stringOne = "Good Morning"; console.log(stringOne); // logs "Good Morning" to the console
We will learn more about strings in a separate post.
So using a boolean, you can check the truthiness or false state of some expression. We will learn more on Booleans in a separate post. But let us see a real quick example to understand a boolean in a nutshell.
const day = "Monday"; const isMonday = day === "Monday"; // If day is Monday, this expression will resolve to true else it will resolve to false. console.log(isMonday);
You can assign null to a variable to denote that currently that variable does not have any value but it will have later on. A null means absence of a value.
console.log(typeof null); // "object" (not "null" for legacy reasons) let someVariable = null; console.log(someVariable); // null
It is the default value of a variable when it is just declared but not assigned an initial value.
let name; console.log(name); // logs undefined to the console let age = 21; age = undefined; console.log(age); // logs undefined to the console.
Comparing null and undefined
When comparing null and undefined using ==, they are considered equal. For example,
console.log(null == undefined); // logs true to the console.
The reason for getting true in the console for the above code snippet is that , == compares values by performing type conversion. Both null and undefined return false. Hence, null and undefined are considered equal.
However, when comparing null and undefined with strict equality comparison using ===, the result is false.
console.log(null === undefined); // logs false to the console
A symbol represents a unique identifier.
A value of this type can be created using Symbol():
const newId = Symbol(); console.log(newId);
You could optionally also pass an argument to the Symbol to provide it some description.
Symbols are guaranteed to be unique. So even if you create many symbols with the exact same description, they are still considered as different values. The description is kind of a label and it does not affect anything.
Check my video on Introduction to Data Types to get more understanding on these:
So this is it for this one. Thanks for reading !