Fireship · @fireship
JavaScript Function - What's your Function?
Uploaded August 6, 2019 · Length 12:27
Summary
JavaScript functions explained, including declarations, expressions, parameters, and arrow syntax.
- javascript functions
- function declarations
- function expressions
- parameters
- arguments
- arrow functions
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
Grossberg it's great to learn because
- 0:04
knowledge is power functions are the
- 0:06
backbone of JavaScript development yet
- 0:08
also one of the most difficult concepts
- 0:09
to master but once you understand
- 0:11
functions everything else in the
- 0:12
language becomes relatively easy we'll
- 0:14
start from the absolute basics then go
- 0:16
into practical examples of arrow
- 0:17
functions closures higher-order
- 0:18
functions recursion and we'll even talk
- 0:21
about some common best practices for
- 0:22
writing high-quality JavaScript code
- 0:24
welcome to episode 4 of the full course
- 0:26
JavaScript function if you're new here
- 0:30
like and subscribe and you can follow
- 0:31
the full free course on fire ship IO now
- 0:34
in order to understand a function let's
- 0:36
start by dissecting it and looking at
- 0:37
its anatomy what we're looking at here
- 0:44
is a function declaration also called a
- 0:46
function definition or statement it
- 0:47
starts with the function keyword then
- 0:49
you need to choose a name for it and you
- 0:51
should choose something that's readable
- 0:52
to other human beings because there's a
- 0:54
good saying there's only two hard things
- 0:55
in computer science cache and validation
- 0:57
naming things and off-by-one errors in
- 1:00
other words choosing the right name for
- 1:01
your function is almost as hard as
- 1:03
making a joke about programming but once
- 1:05
you decide on a name the next step is to
- 1:07
add parentheses and then add any
- 1:08
parameters or inputs to the function you
- 1:11
can think of a parameter as a variable
- 1:13
that this function lot access to when
- 1:15
it's called and then from there we have
- 1:16
curly braces and everything inside is
- 1:18
the function body and that's where you
- 1:20
define all your logic the function body
- 1:22
will typically do one of two things
- 1:24
it will either perform a task or return
- 1:25
a value or possibly both an example of a
- 1:28
function performing a task is a console
- 1:30
log and because there's no return
- 1:32
statement it will implicitly return
- 1:34
undefined but a function body might also
- 1:36
contain a return statement and that
- 1:37
allows us to take the value that was
- 1:39
calculated inside the function body and
- 1:41
set it as a variable now at this point
- 1:43
we've declared a function which
- 1:44
describes what the code will do but in
- 1:46
order to actually execute it we need to
- 1:48
call the function we do that by
- 1:49
referencing the function by its name and
- 1:51
then we pass in actual values as
- 1:53
arguments to the parameters so imagine
- 1:55
you get asked on an interview what is
- 1:57
the difference between a parameter and
- 1:59
an argument you might say something like


