Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- how to write a comments in javascript:
- inline comments:
- (sample script) //this is an inline comment
- multi-line comments:
- /* this is a multi-line comment*/
- javascript data types:
- undefined = something that hasn't been defined
- null = nothing
- boolean = true or false
- string = any sort of text
- symbol = immutable primitive vaule that is unique
- number = number
- object =
- How to use variables:
- The three ways to declare variables:
- 1 let (for example: let myname = "mateocoltura")
- 2 const (for example: const pi = 3.14)
- 3 var (for example: var myname = "mateo", var myname= "8" )
- Difference between var, const, and let:
- var is able to be used troughout your whole program
- let wil only will be used within the scope where you declare it
- const is a variable that should/can never change
- declaring a variable (declaring and assigning in one line) :
- var b = 2;
- assigning a variable (letting it be called a for example):
- var a;
- now i can give a a value without var before it because it has already been assigned:
- a = 7;
- b = a;
- this can be used in the console:
- if var a = 7 when i type: "console.log(a)" it will display 7 in the console
- uninitalized variables:
- var a;
- var b;
- var c;
- initialzed variables:
- var a = 5;
- var b = 10;
- var c = "i am a string" (must always be between quotation marks)
- calculating with initialized variables:
- if "var a = 5;" then "a = a + 1;" equals: "6"
- if "var b = 10;" then "b = b + 5;" equals: "15"
- if "var c = "I am a" then "c = c + "String";" equals: "I am a string!"
- VARIABLE DECLARATIONS AND ASSIGNMENTS ARE CASE SENSITIVE, if you have multiple things to declare to a var you use studlyCapVar by starting the first word with a lowercase and the next words with Uppercase, for example:
- johnLucasBob
- ericaThomasJade
- AppleBottomJeans
- Adding numbers in javascript:
- var sum = 10 + 10;
- Subtracting numbers in javascript:
- var difference = 20 - 10;
- Multiplying numbers in javascript:
- var product = 8 * 1;
- Dividing numbers in javascript:
- var quotient = 66 / 2;
- for example: if "var sum = 10 + 10" then "console.log(sum)" will display the number 20 in the console
- Incrementing numbers:
- if "var myVar = 87;" then you can increment by doing: "myVar++;"
- Decrementing numbers:
- if "var Myvar = 87;" then you can decrement by doing: "Myvar--;"
- Decimal numbers:
- var myDecimal = 0.009
- Multiplying decimal numbers:
- var product = 2.0 * 2.5;
- Dividing decimal numbers:
- var quotient = 4.4 / 2.0;
- Finding a remainder: (the remainder operator gives the remainder of a division of two numbers)
- var remainder = 11 % 3; (=2)
- The remainder operator is often used to determine if a number is even or odd,
- if you can divide a number by 2 and the remainder is 0 that means the number is even
- Compound assignment with augmented addition:
- var a = 3;
- a = a + 12
- shortcut:
- a += 12
- Compound assignment with augmented substraction:
- var a = 11;
- a = a - 6;
- shortcut:
- a -= 6;
- Compound assignemt with augmented multiplication:
- var a = 5;
- a = a * 5;
- shortcut:
- a *= 5
- compound assignemt with augmented division:
- var a = 48;
- a = a / 12
- shortcut:
- a /= 12
- Declaring string variables:
- var myFirstName = "Mateo";
- var myLastName = "Coltura";
- Escaping literal quotes in strings:
- var myStr = "i am a "double quoted" string inside "double quotes"
- what you should do when you want to use quotes inside a string:
- var myStr = "I am a \"double quoted\" string inside \"double quotes\" "
- Quoting strings with single quotes:
- var myStr = "< a href=\"https://www.example.com\" target= \"_blank\">Link</a>
- what you should do is use single quotation marks because you can also use them.
- var myStr = '<a href="https://www.example.com" target="blank">link</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement