Should I use '==' or '==='?


Flag Post

AbhijayS

asked

Should I use '==' or '==='?

1 Answers


[{"insert":"When using ==, only the "},{"attributes":{"bold":true},"insert":"values "},{"insert":"on either side of the '==' are compared. With '===', JavaScript will check that both the values and data types are the same.\n\nFor example, 5 === \"5\" would evaluate to false because "},{"attributes":{"bold":true},"insert":"5 "},{"insert":"is a number data type while \""},{"attributes":{"bold":true},"insert":"5\""},{"insert":" is a string data type.\n\nThis may be useful if the following behavior is not wanted.\nconsole.log('\\n' == 0); // evaluates to true"},{"attributes":{"code-block":true},"insert":"\n"},{"insert":"console.log(' ' == 0); // evaluates to true"},{"attributes":{"code-block":true},"insert":"\n"}]

Your Answer


Feedback