![]() Whenever you use the nullish coalescing operator, an empty string like "" or a 0 will not trigger the default value.Ĭheck the other cases using the JavaScript ? operator. The nullish coalescing operator may come useful anytime. It doesn't matter if you are tinkering with your first portfolio project or if you are starting with React. It is important to remember that null and undefined are the only two cases that will prompt the use of the default value! This is what a nullish coalescing operator (?) will return. ![]() In fact, you can read ANY JavaScript ? operator like this: IF the first value is null/undefined THEN use the default value. Why two examples to explain the JavaScript ? operator? the one on the right side of the ? operator. So, if the value of the first variable (the one on the left side of the ? operator) is undefined, use the default value i.e.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |