-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathscript.js
More file actions
168 lines (121 loc) · 3.1 KB
/
script.js
File metadata and controls
168 lines (121 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// 'use strict';
console.log('💥 hello world 💥');
console.log(compilerTest);
var compilerTest;
// VARIABLES
// Box/container to hold references to values
var hello = "world";
let hello1 = "world1";
const hello2 = "world2";
hello3 = "world3";
console.log(hello, hello1, hello2, hello3);
// var
// Can be used before declared
// Can be reassigned & redeclared
var importantVar = "This is some important code!!";
importantVar = "Something else";
console.log(importantVar);
// global variable
// Makes variable available in places where we don't want it
// Make sure to use var, let or const
global = "I am available everywhere!";
// let
// Cannot be used before declared
// Can be reassigned but not redeclared
let myNumber = 7;
myNumber = 9;
console.log(myNumber);
// const
// Cannot be used before declared
// Cannot be reassigned or redeclared
const myConstNumber = 17;
console.log(myConstNumber);
// Primitives
// Number, String, Boolean, undefined, null
const myNumber2 = 2;
const myNumber2Plus2 = 2 + 2;
const myString = "Some string";
const myString2 = 'Some string';
const myString3 = `Some string`;
const myString4 = "Some " + "string";
const myBoolean = true;
const myBoolean1 = false;
const myUndefined = undefined;
const empty = null;
console.log(myNumber2, myNumber2Plus2);
// Composites
// Objects, Functions, Arrays
const myCar = { make: "Ford" };
const myArray = [1, 2, 3, 4, true];
const myFunc = function() {
// Something here
}
// FUNCTIONS
// Function declaration
function myFunction(string) {
return string + " some more text";
}
console.log(myFunction('Something'));
// Allows Hoisting!
console.log(myHoistedFunction('Hoisting!'));
function myHoistedFunction(string) {
return string + " some more text";
}
// Function expression
//Anonymous/unnamed function
//Not hoisted
const greetMe = function() {
console.log('Hello ' + name)
}
console.log(greetMe('John'))
// Arrow function expressions
const myArrowFunction = ()=> {
return 'Hello from arrow function!'
}
console.log(myArrowFunction())
//The one-liner
const oneLiner = () => 'Hello from one line!'
console.log(oneLiner)
//OBJECTS
//functions in an object are called methods
const myObject = {
key1: 'Hello',
key2: true,
key3: 12345,
key4: () => 'Hello from method!'
}
console.log(myObject)
//Dot notation
console.log(myObject.key1);
// Bracket notation
console.log(myObject['key2']);
//Accessing function/method
console.log(myObject.key4());
const tasks = {
task1: 'make an object',
task2: 'copy code',
task3: 'send to slack'
}
//Object methods
//Object.keys(<object>)
// console.log(Object.keys(task1));
//Object.values(<object>)
//Object.entries(<object>)
//ARRAYS
const myArray1 = Array(1, 2, 3, true, null, {}, Array(1, 2, 3));
const myBracketArray = [1, 2, 3, 'hello']
console.log(myArray1);
const jsFrameworks = ['react', 'angular', 'vue']
//.push()
//Add item to end of array
//.pop()
//Delte item of end of array
//.unshift()
//Add item to beggining of array
//.shift()
//Delete item from begging of array
//For loop
//Executes code x amount of times
for(let i=0; i < 5; i++) {
console.log('Hi');
}