=== 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 set content disposition header for nginx server to force content download

Animated daylight on HTML5 Canvas

How to make a static http server in nodejs using express

JS13K Preparation

Adding Gameover and introduction screen on HTML Canvas