Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

81%
+7 −0
Q&A What's the difference between =, == and === operators in JavaScript?

Assignment = = is the assignment operator. There's nothing much to say here. Abstract Equality == == is abstract equality - it will attempt to perform a type conversion before evaluating equalit...

posted 2y ago by Moshi‭  ·  edited 2y ago by Moshi‭

Answer
#3: Post edited by user avatar Moshi‭ · 2021-07-28T05:36:51Z (over 2 years ago)
Added some headers to make it look nice
  • `=` is the assignment operator. There's nothing much to say here.
  • `==` is abstract equality - it will attempt to perform a type conversion before evaluating equality.
  • E.g.
  • ```javascript
  • 1 == '1'
  • 1 == true
  • null == undefined
  • ```
  • Objects only compare equal if both sides *reference* the same object.
  • Therefore, perhaps counterintuitively,
  • ```
  • var x = {};
  • console.log(x == {}) // False
  • ```
  • `===` is strict equality - it checks that both have the same type and have the same value. The example above would not compare equal if it were using the strict equality operator.
  • Note that `NaN` doesn't compare equal to anything, including `NaN`
  • ```javascript
  • NaN != NaN
  • NaN !== NaN
  • ```
  • Bonus: `Object.is`
  • `Object.is` is even stricter than `===`, requiring *exact* values.
  • ```
  • Object.is(+0, -0) // false
  • ```
  • It is useful for `NaN` though, as `Object.is(NaN, NaN)` returns true.
  • ## Assignment `=`
  • `=` is the assignment operator. There's nothing much to say here.
  • ## Abstract Equality `==`
  • `==` is abstract equality - it will attempt to perform a type conversion before evaluating equality.
  • E.g.
  • ```javascript
  • 1 == '1'
  • 1 == true
  • null == undefined
  • ```
  • Objects only compare equal if both sides *reference* the same object.
  • Therefore, perhaps counterintuitively,
  • ```
  • var x = {};
  • console.log(x == {}) // False
  • ```
  • ## Strict Equality `===`
  • `===` is strict equality - it checks that both have the same type and have the same value. The example above would not compare equal if it were using the strict equality operator.
  • Note that `NaN` doesn't compare equal to anything, including `NaN`
  • ```javascript
  • NaN != NaN
  • NaN !== NaN
  • ```
  • ## Bonus: `Object.is`
  • `Object.is` is even stricter than `===`, requiring *exact* values.
  • ```
  • Object.is(+0, -0) // false
  • ```
  • It is useful for `NaN` though, as `Object.is(NaN, NaN)` returns true.
#2: Post edited by user avatar Moshi‭ · 2021-07-28T05:34:07Z (over 2 years ago)
  • `=` is the assignment operator.
  • `==` is abstract equality - it will attempt to perform a type conversion before evaluating equality.
  • E.g.
  • ```
  • 1 == '1'
  • 1 == true
  • null == undefined
  • ```
  • `===` is strict equality - it checks that both of them are the same type and have the same value.
  • `=` is the assignment operator. There's nothing much to say here.
  • `==` is abstract equality - it will attempt to perform a type conversion before evaluating equality.
  • E.g.
  • ```javascript
  • 1 == '1'
  • 1 == true
  • null == undefined
  • ```
  • Objects only compare equal if both sides *reference* the same object.
  • Therefore, perhaps counterintuitively,
  • ```
  • var x = {};
  • console.log(x == {}) // False
  • ```
  • `===` is strict equality - it checks that both have the same type and have the same value. The example above would not compare equal if it were using the strict equality operator.
  • Note that `NaN` doesn't compare equal to anything, including `NaN`
  • ```javascript
  • NaN != NaN
  • NaN !== NaN
  • ```
  • Bonus: `Object.is`
  • `Object.is` is even stricter than `===`, requiring *exact* values.
  • ```
  • Object.is(+0, -0) // false
  • ```
  • It is useful for `NaN` though, as `Object.is(NaN, NaN)` returns true.
#1: Initial revision by user avatar Moshi‭ · 2021-07-28T05:25:22Z (over 2 years ago)
`=` is the assignment operator.

`==` is abstract equality - it will attempt to perform a type conversion before evaluating equality. 

E.g.

```
1 == '1'
1 == true
null == undefined
```

`===` is strict equality - it checks that both of them are the same type and have the same value.