Friday, 18 August 2017

what does "===" imply in Javascript/Jquery?











I'm trying to understand what is happening here:



 data.toPage = $('div#someID');

if ( typeof data.toPage === "string" ) {
// sth

console.log("hello");
}


So I'm checking for a string am I not? I'm curious because my console "helloes".



Thanks for some input!


Answer



==
This is the equal operator and returns a boolean true if both the operands are equal. JavaScript will attempt to convert different data types to the same type in order to make the comparison. Assuming 'a' to be 2 and 'b' to be 4, the following examples will return a value of true:




a == 2
a == "2"
2 == '2'


===
This is the strict equal operator and only returns a Boolean true if both the operands are equal and of the same type. These next examples return true:



a === 2

b === 4

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...