Difference Between =, == And === In JavaScript

황희윤·2021년 7월 28일
0

Javascript

목록 보기
1/2

Hello! I was curious that why Javascript has triple equals (===) .
I know Python has = and ==, but not ===.
So I searched it up.

Equals to (=) is used for assigning values to a variable.
ex) a=1, b=0

Double equals (==) is used to compare the type of two variables as a boolean
ex) '1'==1, true == '1', false == ''

'1'== 1 is true, because Javascript automatically changes string to number type.

true == '1' is true, because true is equivalent of 1

false == '' is true, because empty string is equivalent of 0 and false is equivalent of 0

Triple equals (===) is comparison operator like double equals,
but triple equals not only compare the type of variables but also the value of variables

true === '1' and 1==='1' are false because '1' is just a string, not a number 1.

'hello' and 'hola' are both have same type which is string, but the values of two strings are different.

NaN is a value which means it's Not a Number.
'a' is a value which represents a. Therefore, the two variable are not same.

If you want to say something about the information, please feel free to write a comment below. Thank you!

profile
HeeYun's programming study

1개의 댓글

comment-user-thumbnail
2022년 10월 18일

Java script and other languages are promoted for the full use of the options. The surface is ensured for the citizens. Skills are visited on https://www.devdiscourse.com/article/education/1788101-3-best-essay-writing-services-in-the-usa for the attentive means for the reforms and opportunities for the suffering in the main ideal paths for the java.

답글 달기