Declaring a variable is the technical term that’s used to describe the process of first creating a variable in a program. You may also hear it called initialization. Creating a variable, declaring a variable, and initializing a variable all refer to the same thing.
Variables in JavaScript can be created in one of two ways:
Using a var keyword:
var myName;
A variable created using a var keyword will have an initial value of undefined unless you give it a value when you create it, such as
var myName = "Chris";
Without a var keyword
myName = "Chris";
When you create a variable without a var keyword, it becomes a global variable. (In order to understand what a global variable means, see the next post.)
No comments:
Post a Comment