Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="description" content="The In's and Out's of Variables">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>Variables</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- /*
- VARIABLES:
- Containers that hold different types of data;
- they're named containers that hold things into memory.
- 1. They can contain primitive as well as complex data types including:
- Strings
- Booleans
- Numbers
- Null
- Objects
- Arrays
- 2. You can change the values that variables hold
- 3. There are two phases that variables go through; declaration and assignment.
- */
- /* To declare a variable is to give it a name; you do this by first
- implementing the keyword var followed by the name and a semicolon.
- */
- // Example:
- 'use strict';
- var myName;
- var myAge;
- /* At the declaration phase variables are automatically set to undefined
- because it has yet to be assigned a value. Javascript basically says "Yes, this
- variable exists but you haven't put anything in it."
- */
- console.log(myName); // prints out undefined
- console.log(myAge); // prints out undefined
- /* To assign a variable is to give it a value after it has been declared;
- you do this by using the = operator and then typing a value to be stored.
- */
- //Example:
- var myCity = 'New Orleans';
- var gender = 'Female';
- console.log(myCity); //prints out "New Orleans"
- // We can also reassign values to variables without having to re-declare them.
- //Example:
- myCity = 'Chicago';
- console.log(myCity); // prints out "Chicago"
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/*
- VARIABLES:
- Containers that hold different types of data;
- they're named containers that hold things into memory.
- 1. They can contain primitive as well as complex data types including:
- Strings
- Booleans
- Numbers
- Null
- Objects
- Arrays
- 2. You can change the values that variables hold
- 3. There are two phases that variables go through; declaration and assignment.
- */
- /* To declare a variable is to give it a name; you do this by first
- implementing the keyword var followed by the name and a semicolon.
- */
- // Example:
- var myName;
- var myAge;
- /* At the declaration phase variables are automatically set to undefined
- because it has yet to be assigned a value. Javascript basically says "Yes, this
- variable exists but you haven't put anything in it."
- */
- console.log(myName); // prints out undefined
- console.log(myAge); // prints out undefined
- /* To assign a variable is to give it a value after it has been declared;
- you do this by using the = operator and then typing a value to be stored.
- */
- //Example:
- var myCity = 'New Orleans'
- var gender = 'Female'
- console.log(myCity); //prints out "New Orleans"
- // We can also reassign values to variables without having to re-declare them.
- //Example:
- myCity = 'Chicago';
- console.log(myCity); // prints out "Chicago"
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement