Created
May 27, 2020 07:39
-
-
Save AviKKi/d9c0100cc8d6e8aada5b19c31b76ed70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SLIDE 1 | |
no if(!rating) rating = "Unrated coontent" | |
no rating = rating || "Unrated content" | |
yes rating = rating ?? "Unrated content" | |
SLIDE 2 | |
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. | |
Unexpected behaviour is seen with logical OR(||) operator, as 0, "", [] etc. are treated as falsy value. | |
In previous example | |
let user = {rating: 0} | |
rating = user.rating || "Unrated content" | |
console.log(rating) // expected 0 but output is Unrated Content | |
SLIDE 3 | |
Browser Support | |
Chrome 80+ | |
Firefox 72+ | |
Edge 80+ | |
safari 13.1 | |
IE No | |
SLIDE 4 | |
LIKE | |
Comment | |
Share | |
Save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment