From the course: Learning the JavaScript Language
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Functions and scope - JavaScript Tutorial
From the course: Learning the JavaScript Language
Functions and scope
- [Instructor] In this video, we're going to talk more about variable scope and how functions relate to it. Here's an example. I'll create a variable called myNum and set it to 32 and another one called myResult which will set to success. Then I can write a function, or in this case, I'm going to copy and paste a function. It's called randomizer and it takes a limit as its argument. Inside the function, I create a variable called randomNumber and assign A randomly generated number to it. Then I create another variable, which is called myNum, just like the one we created out here originally, outside the function, and then assign that the value of the random number which is between zero and that limit that was passed in. Then we're going to log a couple of lines before returning myNum. So back here, I set myNum to 32 and myResult to success and now we're going to invoke this randomizer function, passing in 10 as the limit.…
Contents
-
-
-
-
-
-
-
-
(Locked)
Basic functions4m 20s
-
(Locked)
Arguments and parameters in functions6m 54s
-
(Locked)
More on function arguments5m 3s
-
(Locked)
Objects, references, and functions7m 4s
-
(Locked)
Functions are objects5m 8s
-
(Locked)
Jargon: Scope in JavaScript2m 30s
-
(Locked)
Functions and scope5m 11s
-
(Locked)
Writing shorter functions with arrows3m 12s
-
(Locked)
Three little dots collect the rest4m 14s
-
(Locked)
Callback functions and looping4m 34s
-
(Locked)
-
-