Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
Let's now learn about the new operator 2
2
with the funny name of nullish coalescing operator. 3
3
So in the last video, we used the OR operator 4
4
to set a default value 5
5
in case that the first value was a falsy value. 6
6
So let me bring back that code here, actually. 7
7
So this one, 8
8
but we're only interested in the OR operator here. 9
9
So let's call this one simply guests. 10
10
And so let's again remember what happens here, 11
11
which is when we set numGuests to zero, 12
12
then JavaScript will still take this default value here 13
13
and assign it to guests because zero is a falsy value now, 14
14
and so therefore, we go to the second operand. 15
15
However, fortunately for us, 16
16
there is a very good solution to this, 17
17
and that's the new operator with the very weird name 18
18
of nullish coalescing operator. 19
19
It's an operator that was introduced in ES2020, 20
20
and it works like this. 21
21
So guests, let's call this one Correct now. 22
22
And so it works almost the same way as the OR operator, 23
23
really almost the same, but it will fix or error here. 24
24
So let's see that it does, 25
25
and then I'll explain to you why that is. 26
26
All right, and now indeed, we get zero. 27
27
So we get the real value that is actually here. 28
28
And now if we take it off, only then we get 10, 29
29
which is the default value that we want. 30
30
So why does this work? 31
31
Well, it is because the nullish coalescing operator 32
32
works with the idea or with the concept 33
33
of nullish values instead of falsy values. 34
34
And nullish values are null 35
35
and undefined. 36
36
That's it. 37
37
It does not include a zero 38
38
or the empty string. 39
39
So basically, for the nullish coalescing operator, 40
40
it is as if the zero and the empty string 41
41
were not falsy values 42
42
and were instead truthy values as well. 43
43
But again, this operator does work 44
44
with the principle of nullish values. 45
45
And so all the nullish values 46
46
will short circuit the evaluation here. 47
47
Okay, so only if this was null or undefined, 48
48
only then the second operand here 49
49
would be executed and returned. 50
50
And so right now, that's the case 51
51
as number of guests does not exist, 52
52
so we commented it out here. 53
53
And so now it is undefined, 54
54
and so only then the evaluation continues. 55
55
But again, as we put it back, it now is zero, 56
56
and zero is not a nullish value. 57
57
And therefore, the evaluation here is short circuited, 58
58
and immediately, this first non-nullish value is returned. 59
59
All right, and that's actually all for now 60
60
about this nullish coalescing operator. 61
61
It's a really great and really useful operator, 62
62
even though right now, it might not seem that useful, 63
63
but as we go through the project, 64
64
you will see that it really is.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.