Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value.length == 0 inside of an if statement.

Is there a performance benefit to replacing == with ===?

Any performance improvement would be welcomed as many comparison operators exist.

If no type conversion takes place, would there be a performance gain over ==?

1 Answer

0 votes
by (106k points)

For the comparison we use === and for Equality we use the == operator.

true == 1; 

"2" == 2; 

image

true === 1;

"2" === 2;

image

Now the reason why we use == as equality because the equality operator == does type coercion, which means that the interpreter implicitly tries to convert the values before comparing.

Whereas the ==== operator does not do type coercion, and thus does not convert the values when comparing, and is, therefore, faster as it skips one step.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 14, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...