-
-
Save ndonolli/4984b89c2b50d2c810a80d07a85819da to your computer and use it in GitHub Desktop.
Variables[A primer on variables]// source http://jsbin.com/zifara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[A primer on variables]"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Variables</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/* | |
VARIABLES: | |
Variables are used in programming to store things into memory and retrieve at other points during the runtime of the program. A variable can point to any data type (Number, String, Array, Object, etc.) and can be changed and reassigned at later points. | |
To create a variable for the program to store in memory is called DECLARATION. This is easy! It can be done using the javascript keyword 'var': | |
*/ | |
var myVariable; | |
/* | |
That's pretty neato. Now we can refer to this variable within our code. Let's try logging myVariable to the console. | |
*/ | |
console.log(myVariable); | |
// > undefined | |
/* | |
It seems that myVariable is undefined. We have not assigned a value to it and thus has nothing to print. To do this, we must INITIALIZE myVariable with the '=' operator. | |
*/ | |
myVariable = 'I am a variable!'; | |
console.log(myVariable); | |
// > 'I am a variable!' | |
/* | |
We can reassign this variable to another value using the assignment operator, like we did above. | |
*/ | |
myVariable = 'I vary from day to day'; | |
console.log(myVariable); | |
// > 'I vary from day to day' | |
/* | |
The machine reads our code the same way we do - top to bottom. If a variable is reassigned later in the run cycle of the code, it will refer to its last assignment. | |
Variables help us remember what certain data or objects in our code represents. They can be named anything we choose, and they can represent data types other than strings. | |
*/ | |
var myVariable = 1; | |
var myVariable = true; | |
myVariable = "something else"; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/* | |
VARIABLES: | |
Variables are used in programming to store things into memory and retrieve at other points during the runtime of the program. A variable can point to any data type (Number, String, Array, Object, etc.) and can be changed and reassigned at later points. | |
To create a variable for the program to store in memory is called DECLARATION. This is easy! It can be done using the javascript keyword 'var': | |
*/ | |
var myVariable; | |
/* | |
That's pretty neato. Now we can refer to this variable within our code. Let's try logging myVariable to the console. | |
*/ | |
console.log(myVariable); | |
// > undefined | |
/* | |
It seems that myVariable is undefined. We have not assigned a value to it and thus has nothing to print. To do this, we must INITIALIZE myVariable with the '=' operator. | |
*/ | |
myVariable = 'I am a variable!'; | |
console.log(myVariable); | |
// > 'I am a variable!' | |
/* | |
We can reassign this variable to another value using the assignment operator, like we did above. | |
*/ | |
myVariable = 'I vary from day to day'; | |
console.log(myVariable); | |
// > 'I vary from day to day' | |
/* | |
The machine reads our code the same way we do - top to bottom. If a variable is reassigned later in the run cycle of the code, it will refer to its last assignment. | |
Variables help us remember what certain data or objects in our code represents. They can be named anything we choose, and they can represent data types other than strings. | |
*/ | |
var myVariable = 1; | |
var myVariable = true; | |
myVariable = "something else";</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
========== | |
VARIABLES: | |
========== | |
Variables are used in programming to store things into memory and retrieve at other points during | |
the runtime of the program. A variable can point to any data type (Number, String, Array, | |
Object, etc.) and can be changed and reassigned at later points. | |
To create a variable for the program to store in memory is called DECLARATION. This is easy! | |
It can be done using the javascript keyword 'var': | |
*/ | |
var myVariable; | |
/* | |
That's pretty neato. Now we can refer to this variable within our code. Let's try logging | |
myVariable to the console. | |
*/ | |
console.log(myVariable); | |
// > undefined | |
/* | |
It seems that myVariable is undefined. We have not assigned a value to it and thus has | |
nothing to print. To do this, we must INITIALIZE myVariable with the '=' operator. | |
*/ | |
myVariable = 'I am a variable!'; | |
console.log(myVariable); | |
// > 'I am a variable!' | |
/* | |
We can reassign this variable to another value using the assignment operator, like we did above. | |
*/ | |
myVariable = 'I vary from day to day'; | |
console.log(myVariable); | |
// > 'I vary from day to day' | |
/* | |
The machine reads our code the same way we do - top to bottom. If a variable is reassigned | |
later in the run cycle of the code, it will refer to its last assignment. | |
Variables help us remember what certain data or objects in our code represents. They can | |
be named anything we choose, and they can represent data types other than strings. | |
*/ | |
var myVariable = 1; | |
var myVariable = true; | |
myVariable = "something else"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment