What is triple === in javascript?
Show
Learn equality in JavaScript in 3 minutesUdemy Black Friday Sale — Thousands of Web Development & Software Development courses are on sale for only $10 for a limited time! Full details and course recommendations can be found here. The ProblemJavaScript has two visually similar, yet very different, ways to test equality. You can test equality with Triple EqualsWhen using triple equals Lets look at a couple examples of strict equality. In this first example we’re comparing the number 5 with the number 5. As expected, 5 === 5 With this in mind, we can look at two more examples that will return 'hello world' === 'hello world' Awesome. Now lets
take a look at some examples that will return In this example we’ll compare the number 77 to the string value of 77. This means our operands will have the same value, but a different type. This will return 77 === '77' Here are two additional examples: 'cat' === 'dog' Awesome! Again, the key takeaway for triple (strict) equality is that both the type and the value we are comparing have to be the same. Double equalsWhen using double equals in JavaScript we are testing for loose equality. Double equals also performstype coercion. Type coercion means that two values are compared only after attempting to convert them into a common type. An example will illustrate this. Recall earlier when we tested the following with strict equality: 77 === '77'
77 == '77' You can see we get Lets look at one more example. Recall earlier when we tested with strict equality if false === 0 This is obviously false. However, if we run the same equation with loose equality… false == 0 We get Falsy ValuesOkay, so why does Type coercion will actually convert our zero into a false boolean, then There are only six falsy values in JavaScript you should be aware of:
Falsy Value ComparisonThe following you can consider to be ‘rules’ of falsy values. These are things you should ultimately memorize if you will be working with JavaScript often.
When comparing any of our first three falsy values with loose equality, they will always be equal! That’s because these values will all
coerce into a false == 0 2. When comparing null == null If you try to compare 3. Lastly, NaN == null Key Takeaways
Closing Notes:Thanks for reading! If you’re ready to finally learn Web Development, check out the The Ultimate Guide to Learning Full Stack Web Development in 6 months. I publish 4 articles on web development each week. Please consider entering your email here if you’d like to be added to my once-weekly email list, and follow me on Twitter. If this post was helpful, please click the clap 👏button below a few times to show your support! ⬇⬇What does triple === mean?When using triple equals === in JavaScript, we are testing for strict equality. This means both the type and the value we are comparing have to be the same.
What is triple equal in JavaScript?JavaScript provides three different value-comparison operations: === — strict equality (triple equals) == — loose equality (double equals)
What is the difference between double == and triple === equals?Double Equals ( == ) checks for value equality only. It inherently does type coercion. This means that before checking the values, it converts the types of the variables to match each other. On the other hand, Triple Equals ( === ) does not perform type coercion.
What does === in JavaScript mean?The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
|