Skip to content

Instantly share code, notes, and snippets.

Created June 24, 2016 18:35
Show Gist options
  • Save anonymous/5f980d41a6c10958044fcd9ced097eb7 to your computer and use it in GitHub Desktop.
Save anonymous/5f980d41a6c10958044fcd9ced097eb7 to your computer and use it in GitHub Desktop.
Variables [A primer on variables] // source http://jsbin.com/zifara
<!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>
/*
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