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
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...
Answer
#3: Post edited
- `=` 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
`=` 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
`=` 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.