All language subtitles for 7- Functions

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
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
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 category

of reference types, you have learned about objects and arrays. Now,

let's take a look at functions. Functions are one of the fundamental

building blocks in JavaScript. A function is basically

a set of statements that performs a task or calculates

a value. Let show you a couple examples. So I'm going to

declare a function using the function keyword. Now we need to give it

a name, let's call that greet. After that we need to add

parenthesis, that's part of the syntax for declaring functions.

And then curly braces. Now what we have here,

inside the curly braces is what we refer to as the body of

this function. And this is where we add all the statements to define

some kind of logic in our application. For example,

The logic for this function should be to display a message

on the console. So here we can add console.log

Hello World.

Now note that here we have a statement, so we terminate it with a

semi colon, but when we are declaring a function, we don't need to add

semi colon at the end, because we are not declaring it like a

variable like this. Okay? This is a function

declaration, right? So, now we have a function

we can call this function like this. So we add the

name of the function, and parenthesis again, and then

semi colon to indicate that this is a statement. Save the

changes, now we have Hello World on the console. But that's pretty boring,

what would we do with this? Let me show you how to make this more interesting.

Our functions can have inputs, and these inputs can change

how the function behaves. So, let's say

instead of displaying Hello World we want to display the name of the person

here. Like Hello Jon. So we can add

a variable here in between parenthesis,

we refer to tis variable as a parameter. So,

this greet function has one parameter called name, and essentially

name is like a variable that is only meaningful

inside of this function. So inside of this function we can work with this name variable

but it will not be accessible outside of this function.

Now name is an input to this function. So instead of

displaying Hello World you can display Hello then add

a plus here to concatenate two strings.

So, we can add name after. Now,

when calling the greet function, we need to pass a value for the

name variable, or name parameter more accurately. So,

we can pass John here, now we refer to this

as an argument. So John is an argument

to the greet function and name is a

parameter of the greet function it's one of the things that a lot of programmers

know. They don't know the difference between a parameter and an argument.

So a parameter is what we have here at the time of declaration,

but the argument is the actual value of supply for that

parameter. Okay? Now, I save the changes,

so we have Hello John. Now we can reuse this function

but with a different input. So, we can

change this line here and change John to Mary. Save the changes

now we have two different messages on the console.

Now a function can have multiple parameters. So here we can have

separate parameters using a comma, so let's add another

parameter like lastName, now

we can change our console.log add a space here,

and then display the lastName.

Now, when calling this greet function, we should pass

another argument for the last name. Well let's see what happens if we don't

do this. So I'm going to save the changes, see what we got

Hello John undefined. Because as I told you before

that the fault value of variables in JavaScript is undefined.

So because we did not pass a value for the last name,

by default it's undefined. So I'm going to pass

another argument here, we separate them using comma

John Smith and we don't need this second call to the

greet function. Save the changes, now we have Hello

John Smith.

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