Course Home | What are Operators? | Code Example(s)
The majority of the operators in Node are explained in the Programming Basic courses. There are examples of operates in the code example. However, there are a few additional operators that are worth discussing:
The first is how Node handles equality. There are two ways in which you can check for equality between values, one uses two equals and the other uses three equals that are shown in the example below:
// Using two equal signs will return true for
// both of these comparisons
console.log(10 == "10");
console.log(10 == 10);
// Using three equals will return false for the
// first example but return true for the second
// example
console.log(10 === "10");
console.log(10 === 10);
If you don’t know which one to use then use the three equal signs.
Another operator unique to Node is typeof
. By putting typeof
in front of a variable or value, then the type of the variable or value is returned:
// Demonstration of the typeof operator
console.log(typeof "Mark"); // returns String
console.log(typeof 1); // returns Number
console.log(typeof true); // returns Boolean
Comments