Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Variables-our friends in the age of repetition
- Variables are placeholders which allow programs to easily recall
- information or actions, alter them, and implement complex operations
- in a clear concise manner. They can be thought of as containers for
- holding values of any data type including numbers, strings, booleans,
- and even functions or objects.
- */
- /*declaring a variable called num1 with "var" keyword
- this simply creates a place in memory which can then be assigned to
- hold a value in the future. Variables declared in the "global scope" or
- outside of a function are stored in the global "window" object and
- useable throughout the program.
- */
- "use strict";
- var num1;
- console.log(num1);//will log "undefined"
- /*variables that have not yet been assigned a value are set to
- undefined by javascript, it is bad practice to set a value to
- undefined yourself although completely possible as it makes
- debugging and searching out errors more difficult
- */
- //assigning a value to the variable "num1" using the "=" assignment
- //operator.
- num1 = 10;
- console.log(num1);//will log 10
- num1 += 10;
- console.log(num1);//will log 20 after altering the numeric value
- //changing the value of a variable
- num1 = "ten";
- console.log(num1);//here the value is completely changed to a string
- // this will log "ten"
- //variables can be changed from numbers to strings or other data
- // types quickly and easily, and their assigned values will called up
- // in the context of their scope.
- /*
- In addition to using variables as containers, we can also call utilize
- "constants" and "lets" to hold values, these too can accept any data type
- but they behave a bit differently than variables.
- */
- //testing testing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement