Operators in Node

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

Next Lesson ➔

Mark Winteringham's photo

Mark Winteringham


Mark Winteringham is a tester, toolsmith and the Ministry of Testing DojoBoss with over 10 years experience providing testing expertise on award-winning projects across a wide range of technology sectors including BBC, Barclays, UK Government and Thomson Reuters. He is an advocate for modern risk-based testing practices and trains teams in Automation in Testing, Behaviour Driven Development and Exploratory testing techniques. He is also the co-founder of Software Testing Clinic a community raising awareness of careers in testing and improving testing education. You can find him on Twitter @2bittester.