Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Finally, the course compares how code is written in several different languages, the libraries and frameworks that have grown around them, and the reasons to choose each one.
What's going to happen is we will jump into the function, we will create the variable, and we will pop up the alert box with the contents of that variable which is 500. Control returns to right after we called it and if try and pop up the content of x again, this will be regarded as undefined. It will say I don't know what x means, because the x variable is not available outside simple function. This is because variables declared inside the functions are referred to as local variables.
They have local scope. They are only available within the opening and closing curly braces of that function. If I need to have the contents of this visible outside, I could do a couple of things. One is I could return a value using the Return keyword and we saw that little earlier. The other way that I could do it do is to declare, to create the variable outside the function. So up at the top I create var x. That's outside all functions and that's referred to as a global variable. That means we could just use the word x to refer to it anywhere, whether I'm inside a function or outside a function.
But with other languages variable scope can apply on those levels too. So you have to be quite careful about where your variables are defined and who can get to them.
Find answers to the most frequently asked questions about Foundations of Programming: Fundamentals.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.