If it checks each character of a string, it can break the loop before. But I don't know how it works internally.
Example :
if(stringA === stringB)
or
if(!(stringA !== stringB))
Which is the most faster ?
If it checks each character of a string, it can break the loop before. But I don't know how it works internally.
Example :
if(stringA === stringB)
or
if(!(stringA !== stringB))
Which is the most faster ?
Here I did some simulations for you to see for yourself when which operation is faster than the other one. Feel free to play around with it.
// ===
console.time();
console.log("1 === 1", 1 === 1);
console.timeEnd();
console.time();
console.log("1 === '1'", 1 === '1');
console.timeEnd();
// !==
console.time();
console.log("1 !== 1", 1 !== 1);
console.timeEnd();
console.time();
console.log("1 !== '1'", 1 !== '1');
console.timeEnd();
To sum it up roughly, !==
is faster than ===
.