Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* String: Any form of text */
- /*Object: Stores a lot of key value pairs*/
- /* declaring variables */
- var myName = "Beau"
- /*can be used throughout program*/
- myName = 8
- let ourName = "freeCodeCamp"
- /* may only be used within scope of where you declare that*/
- const pi = 3.14
- /*can never change*/
- var a;
- /* declaring a variable, called a */
- var b =2;
- /*declaring a, assigning 2*/
- a = 7;
- /* a has already been declared*/
- b = a;
- /* you have assigned contents of a to b*/
- /*initializing a variable to an inital value at the same time it's declared*/
- var a =9;
- /* a: declare, 9: initizing*/
- /* adding/subtracting numbers */
- var sum = 10 + 10;
- console.log(sum)
- var difference = 20 - 10;
- var product = 8 * 10;
- var quotient = 66/2;
- /*Incrementing numbers*/
- /* refers to adding 1 to it*/
- var myVar = 81;
- myVar = myVar + 1;
- /*or*/
- myVar++;
- /*decrementing numbers*/
- /* minus 1 to it*/
- var dcVar = 11;
- dcVar = dcVar - 1;
- /*or*/
- dcVar--;
- /*decimal numbers*/
- var myDecimal = 5.7;
- var secondDecimal = 0.0007;
- /*Multiplying decimals*/
- var product = 2.0 * 2.5;
- console.log(product)
- /*Dividing decimals*/
- var quotient = 6.4/2.0;
- /*finding the remainder*/
- var remainder;
- remainder = 11 % 3;
- 1821
- ////////
- Variables are used to store data temporarily
- - Data is stored somewhere, and give that memory location a name
- - With this name, you may read the data and at a given location
- A variable = box
- What's inside the box = Value that we assign to variable (data)
- Strings are a sequence of characters.
- Rules of naming variables
- - Do not use prexisting keywords used already
- - Meaningful, should be clear instead of a1, b and c
- - cannot start with a number (1name etc)
- - cannot contain space or hyphen (-)
- - case sensitive
- To declare multiple variables
- let firstName = "NumberOne";
- let lastName = "NumberTwo";
- value of variables (let) can change, but
- the value of a constant cannot.
- If you don't need to reassign, constant should be used.
- If you do, use let
- undefined: if value is not initalized, by default, its value is undefined
- null is used to clear value of variable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement