=== or == JavaScript comparison operator

triple equal === strict and double equal == not type strict are two of JavaScript comparison operators blatantly they are almost the same with an exception.

== operator
this type of comparison operator is suitable for basic comparison between two items it's not type strict and normally discouraged unless otherwise and here's why i say so.
Take for instance
console.log((1 == "1")) // returns true
regardless of the fact that "1" is a string and 1 is a Number
because "1" is type casted  to a Number before comparison between the two values is done
Take for instance
var one = 1;
// console.log(typeof one) // Number
It's not a matter of concern neither is it a bug it's because JavaScript is a dynamic typed programming language.

=== or strict operator
triple equal sign operator or strict operator is an operator that takes account of types of values before evaluating their similarities unlike the double equal sign operator strict operator is a secure and recommended method of comparing two values here's an account.
Take for instance
console.log((1 === "1")) // returns false unlike in the previous test the strict operator won't return true because clearly one of the two values is a number while the other is not a number it's a string.

conclusion and final remarks
use strict === operator whenever possible it's less error prone


Popular posts from this blog

How to create zip archives in nodejs

Open-graph meta data tags introdution

What is 'this.' keyword in JavaScript

How to get user's ip address in JavaScript

How to build a twitter retweet bot using JavaScript