Do you find difficulty choosing between =, == & === ?

Assigning Operator (=)

It assigns the value to the variable.

const firstName = ‘Prashant’;
const favNumber = 13;

Loose Equality Operator (==)

This operator compares two values & return true if they are equivalent or f…


This content originally appeared on DEV Community and was authored by Prashant Patel

Assigning Operator (=)

It assigns the value to the variable.

const firstName = 'Prashant';
const favNumber = 13;

Loose Equality Operator (==)

This operator compares two values & return true if they are equivalent or false if they are not.

function equality(value) {
     if(value == 13) {
          return 'Equal';
     }
     return 'Not Equal';
}

In addition, it also compares two different data types (numbers & strings).

It is called as Type Coercion.

1 == '1' /* This will return true with the Loose Equality Operator. */

Strict Equality Operator (===)

Unlike the Equality Operator, it does not compare two different data types.

Otherwise, it works similarly to Loose Equality Operator.

1 === '1' /* This will return false in case of the Strict Equality Operator. */

More Examples

var favBook = 'Sapiens'; /* Assigns the value to the variable */

const 13 == '13'; /* It will perform a type conversion and it will return true. */

const 13 ==='13' /* It will not perform type conversion. Hence, it will return false. */
Hope you found it helpful. Please let me know.
Why not connect on Twitter?


This content originally appeared on DEV Community and was authored by Prashant Patel


Print Share Comment Cite Upload Translate Updates
APA

Prashant Patel | Sciencx (2021-06-19T11:02:56+00:00) Do you find difficulty choosing between =, == & === ?. Retrieved from https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/

MLA
" » Do you find difficulty choosing between =, == & === ?." Prashant Patel | Sciencx - Saturday June 19, 2021, https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/
HARVARD
Prashant Patel | Sciencx Saturday June 19, 2021 » Do you find difficulty choosing between =, == & === ?., viewed ,<https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/>
VANCOUVER
Prashant Patel | Sciencx - » Do you find difficulty choosing between =, == & === ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/
CHICAGO
" » Do you find difficulty choosing between =, == & === ?." Prashant Patel | Sciencx - Accessed . https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/
IEEE
" » Do you find difficulty choosing between =, == & === ?." Prashant Patel | Sciencx [Online]. Available: https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/. [Accessed: ]
rf:citation
» Do you find difficulty choosing between =, == & === ? | Prashant Patel | Sciencx | https://www.scien.cx/2021/06/19/do-you-find-difficulty-choosing-between/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.