All language subtitles for 008 More on Variable Initialization_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

In the last section, we finished up our constructor function and tried to run our code, but we got

this nasty error message that said null underscore methods add is not a function.

And so just based on the presence of the word add right here, I'm going to assume that the error is

coming from this line of code just because I see the word add.

So let's talk about what's going wrong right here.

And it's going to tie back into a topic that we discussed much earlier inside this course.

So I want to remind you about this diagram that we looked at way before.

In this diagram, we broke down a single declaration and initialization of a variable.

We had said that to the left of the equals sign.

We went through a process called variable declaration.

And then by putting in the equals and some value over here to the right, we went through the process

of initialization, which was to actually assign a value to that variable we created.

We also took a look at a diagram that was this one right here, so we had said that when we create that

variable or when we declare it, what we're really doing is creating kind of a reference inside the

memory of our computer.

And that reference has the ability to kind of point over to some other value that also exists inside

of memory.

So how does this relate to the error message we just saw?

Well, let's look at this line of code right here.

On this line, we declared a new field tied to our deck class called Cartes, this line of code right

here is solely a variable or a field initialization.

So as we said just a moment ago, initialization is just the fact of saying, hey, there's a variable

out here called blah, and here is its type.

So what we really just did was to declare a new variable with a type of list that contains a bunch of

different cards.

And it has a name of Cartes.

But what we did not do was any type of variable initialization, we did not set any value to this variable.

So if we think about how this variable currently exists inside of memory, as our program stands right

now, it kind of looks a little something like this.

We've got that Kurts variable over here to the right left hand side, excuse me, but then it has not

been initialized yet.

We've not said, OK, and here's the value that is assigned to that variable.

Whenever we declare a variable and do not initialize it, which is what we're doing right now with cards,

that variable gets a default value of null inside of our application.

And so that's what you're seeing right here with this error message.

The error message, says James, which is short for JavaScript null underscore methods at so no right

here is really the keyword.

It says null because we declared this field right here or we declared this variable, but we did not

actually assign a value to it.

And so by default, if we do not assign a value, we get null for that value or for that variable instead.

So when we call it cardstock ad, we're essentially saying no dot ad and then we try to pass in the

card.

And of course, NULL does not have a function called AD, which is why we see this error message.

OK, so that might be way more detailed.

And you want to know, but I can almost guarantee you this is an error message that you're going to

see on your own, especially in your own projects as you get started with.

So I wanted to put in a little bit of discussion about why you're seeing this error message now to fix

this error.

We can do a very simple thing.

Remember what we did back here?

We had said that we do our variable declaration and then our initialization.

So that's exactly what we're going to do.

We're going to make sure that we initialize that variable.

So to initialize that variable.

Here's my class right here.

Here is the variable declaration to initialize it, we'll put in our equals and then we're going to

assign an empty list to this thing to assign an empty list.

We just put down square.

Brace's like so.

So now we've got the full process, we do our variable declaration, we then initialize it and then

down inside the constructor, when we call the add method that is supposed to be a part of any list,

object cards is no longer null.

It is now an initialized list and the ADD function exists on that list and we should be good to go.

So let's try running this code now and just verifying that we do not get an error message.

OK, so no message anymore.

We don't see any output, but that's totally fine because we're not currently doing any logged statements

or anything like that.

OK, so in this section, we spoke a little bit about how whenever we declare a variable, it gets a

default value of null and it's only when we actually initialize the variable do we get a usable value

assigned to it.

So now that we've covered that kind of corner case, let's continue in the next section.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.