From the course: JavaScript: Best Practices for Functions and Classes

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Avoid == and !=

Avoid == and != - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Avoid == and !=

- [Instructor] If you're coming to JavaScript from a language like Python, you might see JavaScripts double equals equality and inequality operators and think you've found a commonality between the languages but JavaScript actually has multiple types of equality operators and your code will be more reliable if you break the habit of using the two character operators which are known as loose equality operators. The loose equality operators employ type coercion to approximate comparisons between values that may be of different data types. As a result, comparing values may give you results you don't expect and may add an extra challenge to debugging. JavaScript includes a second set of equality operators that use three characters. These are known as the strict equality operators and it's a good practice to get in the habit of using these. These operators don't perform coercion. As a result, they're type safe. If two operands are…

Contents