|
1 | 1 | # JavaScript Cheatsheet
|
2 | 2 |
|
3 | 3 |
|
4 |
| -###JavaScript (or JS) |
| 4 | +## JavaScript (or JS) |
5 | 5 |
|
6 | 6 | It is a popular programming language commonly used to create interactive effects within web browsers.
|
7 | 7 |
|
8 | 8 |
|
9 |
| -###variable |
| 9 | +## variable |
10 | 10 |
|
11 | 11 | A place to store values, can store any kind of information (data types): numbers, words, collections of data
|
12 | 12 |
|
13 | 13 |
|
14 |
| -###undefined variable |
| 14 | +### undefined variable |
15 | 15 |
|
16 | 16 | A variable that has no value
|
17 | 17 |
|
18 |
| -###to declare variable |
| 18 | +### to declare variable |
19 | 19 |
|
20 |
| -To create a variable - done by using ‘ var variable-name = value ’ |
| 20 | +To create a variable - done by using: |
21 | 21 |
|
| 22 | +``` |
| 23 | +var variableName = value; |
| 24 | +``` |
22 | 25 |
|
23 |
| -###to initialize variable |
| 26 | + |
| 27 | +### to initialize variable |
24 | 28 |
|
25 | 29 | Set (give) some value to variable.
|
26 | 30 |
|
27 |
| -###string |
| 31 | +## value types |
| 32 | + |
| 33 | +### string |
28 | 34 |
|
29 | 35 | A set of characters, word(s), phrase. To initialize variable with a string you need to put this string into quotes.
|
30 | 36 |
|
31 |
| -###boolean |
| 37 | +### boolean |
32 | 38 |
|
33 | 39 | Boolean variable represent a logical value True or False
|
34 | 40 |
|
35 | 41 |
|
36 |
| -###array |
| 42 | +### array |
37 | 43 |
|
38 | 44 | An ordered list of values, can store different types of data inside
|
39 | 45 |
|
40 | 46 |
|
41 |
| -###operator |
| 47 | +### operator |
42 | 48 |
|
43 | 49 | Mathematical operators, such as: +, -, *, /, >, <, = etc
|
44 | 50 |
|
45 | 51 |
|
46 |
| -###comments |
| 52 | +## comments |
| 53 | + |
| 54 | +Comments are some notes that you can leave for yourself or another person, a note that a computer will not read. You can write a comment on a new line or on the same line after code as so: |
47 | 55 |
|
48 |
| -Comments are some notes that you can leave for yourself or another person, a note that a computer will not read. You can write a comment on a new line or on the same line after code as so: //I’m your comment |
49 |
| -Single line comment starts with // |
50 |
| -Multi line comment are placed between /* .. */ |
| 56 | +``` |
| 57 | +// I’m your comment |
| 58 | +``` |
| 59 | +Single line comment starts with `//` |
| 60 | +Multi line comment are placed between `/* .. */` |
51 | 61 |
|
52 | 62 |
|
53 |
| -###function |
| 63 | +## function |
54 | 64 |
|
55 | 65 | A separable, reusable piece of code. It takes some input, does some manipulation on it and returns us an output.
|
56 | 66 |
|
57 | 67 |
|
58 |
| -###to declare function |
| 68 | +### to declare function |
59 | 69 |
|
60 | 70 | To create a function
|
61 | 71 |
|
62 |
| -###argument |
| 72 | +### argument |
63 | 73 |
|
64 | 74 | A value input that functions can accept
|
65 | 75 |
|
66 | 76 |
|
67 |
| -###if/else statement |
| 77 | +## if/else statement |
68 | 78 |
|
69 |
| -‘If’ used to decide which lines of code to execute, ‘else’ - to give alternative set of instructions. Example: if(x > 5) {console.log”X bigger than 5”}; else {console.log”X smaller than 5”}; |
| 79 | +`if` used to decide which lines of code to execute, `else` - to give alternative set of instructions. |
70 | 80 |
|
| 81 | +Example: |
71 | 82 |
|
72 |
| -###while loop |
| 83 | +``` |
| 84 | +if (x > 5) { |
| 85 | + console.log("X bigger than 5"); |
| 86 | +} |
| 87 | +else { |
| 88 | + console.log("X smaller than 5"); |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +## Iterating/Loops |
| 93 | + |
| 94 | +### while loop |
73 | 95 |
|
74 | 96 | It repeats code over and over again until some condition is met.
|
75 | 97 |
|
76 | 98 |
|
77 |
| -###for loop |
| 99 | +### for loop |
| 100 | + |
| 101 | +This loop is similar to ‘while loop’, just with a set amount of repetition. You declare counter in the statement as so: |
78 | 102 |
|
79 |
| -This loop is similar to ‘while loop’, just with a set amount of repetition. You declare counter in the statement as so: for(var i = 0; i < 5; i++){do something 5 times}; |
| 103 | +``` |
| 104 | +for (var i = 0; i < 5; i++) { |
| 105 | + do something 5 times |
| 106 | +} |
| 107 | +``` |
80 | 108 |
|
81 | 109 |
|
82 |
| -###infinite loop |
| 110 | +### infinite loop |
83 | 111 |
|
84 | 112 | A loop that does not stop and it’s a loop that you need to avoid. Each loop should have some condition so it can stop.
|
85 | 113 |
|
86 | 114 |
|
87 |
| -###object |
| 115 | +## object |
88 | 116 |
|
89 | 117 | A collection of properties
|
90 | 118 |
|
91 | 119 |
|
92 |
| -###event |
| 120 | +## event |
93 | 121 |
|
94 | 122 | A type of object that is created when a user interacts with a web page. For example, JavaScript creates an event when a user clicks on a button.
|
95 | 123 |
|
96 | 124 |
|
97 |
| -###CSS |
| 125 | +## CSS |
98 | 126 |
|
99 | 127 | Stands for Cascading Style Sheets. CSS describes how HTML elements are to be displayed on screen. It is presentation.
|
100 | 128 |
|
101 | 129 |
|
102 |
| -###HTML |
| 130 | +## HTML |
103 | 131 |
|
104 | 132 | Stands for Hyper Text Markup Language. It is a structure of the elements on the page.
|
105 | 133 |
|
106 | 134 |
|
107 |
| -###DOM |
| 135 | +## DOM |
108 | 136 |
|
109 | 137 | Stands for Document Object Model. It defines the logical structure of documents and the way a document is accessed and manipulated.
|
110 | 138 |
|
111 | 139 |
|
112 |
| -###scope |
| 140 | +## scope |
113 | 141 |
|
114 | 142 | Scope is the set of variables, objects, and functions that you can access.
|
115 | 143 |
|
116 | 144 |
|
117 |
| -###console |
| 145 | +## console |
118 | 146 |
|
119 | 147 | A method of interacting with the system. In order to write to the browser console, you could use console.log(‘Hello World’). This would write Hello World in the browser console.
|
0 commit comments