Development Tools Website Optimization Chrome DevTools Basics The Console Panel

stephen miller
stephen miller
5,907 Points

quick question about operators

I took another course on js and jquery and the teacher explained that when using the 'equals operator' unlike Java, you use 3 equals signs === instead of 2. However in the console you were only using 2 and it was working fine, am i missing something? :0 thanks!

3 Answers

Niclas Valentiner
Niclas Valentiner
8,947 Points

The difference between == and === is that === also compares the variable type.

var a = 1
var b = '1'


a == b  //returns true
a === b // returns false, one is a string and the other is an integer
Jeremy Castanza
Jeremy Castanza
12,075 Points

Generally speaking, you're better off using three equal signs. It'll get you into less trouble and will help you to debug your programs more easily.

Eddy Yi
Eddy Yi
8,746 Points

I heard it is better to use three equal sign every time you work in JS.