-
Notifications
You must be signed in to change notification settings - Fork 0
/
introjs.js
140 lines (112 loc) · 3.49 KB
/
introjs.js
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
// *************** Primitive Data Types ****************************************
// - Number
// - String
// - Boolean
// - Undefined
// - Null
// - Symbol
//*************** Numbers ******************************************************
4
9.3 // float
-10
// type a number, number is spit back out
// basic math
4 + 100
40 - 6
76 * 2
9 / 3
// Modulo or "mod"
9 % 3
// JS follows the order of operations
7 * (8 + 11) - 3
//*************** Strings ******************************************************
"Salt and Pepper Kettle Chips"
"Hello world"
"100"
// single of double quotes
"Double"
'Single'
// concatenation (returns a single string)
"I made" + " a sentence!"
// escaping out of the quotes in a string
// "My mother said "do you want meatloaf?""
"My mother said \"do you want meatloaf?\" "
//*************** Booleans *****************************************************
True
False
// result of a query or comparison, etc.
// = vs == or ===
// strict vs loose equality
4 == 4
7 == 4
"4" == 4
"4" === 4
// Bang operator
"4" !== 4
// Null and Undefined
null
undefined
// *************** Variables ***************************************************
// Variables are like a piece of tupperware ...
var catName = "Raisins"
var age = 3
var isCute = true
"Have you met " + catName + "?"
`Have you met ${catName}?`
// String interpolation. Same end result of concatenation, but less syntax in the end.
`In 5 years, she will be ${( age + 5 )}`
// Rather than...
"In 5 years, she will be " + (age + 5)
// reassign variables (putting something else in the same tupperware)
var isCute = false
// DATA TYPES - VARIABLE MINI CHALLENGES
// ************** Built-in methods *********************************************
// Parentheses are a call to action ()
// lots of things can be executed in your code with a single call to action
alert("Hi!")
prompt("how old are you?")
"Raisins".charAt(5) // "n"
"Raisins".length() // 7
"Raisins".includes("sins") // true
// ************** Comparison Operators *****************************************
// equality operator
true == false // false
3 == "3" // true
// strict comparison
true === false // false
3 === "3" // false
// ************** Relational Operators *****************************************
// greater than
2 > 0 // true
// less than
4 < 8 // true
// greater than or equal to
0 >= 2 // false
// less than or equal to
-4 <= 0.8 // true
// ************** Logical Operators ********************************************
// and
true && false // false
true && true // true
// or
true || false // true
false || false // false
// not
!true // false
!false // true
true != false // true
true != true // false
!(true && false) // true
!(true && false) // true
// ************** Undefined ****************************************************
// If a variable is created but not assigned a value, the variable is undefined.
// ************** Null *********************************************************
// Null is equal to nothing else in your program. It is not zero, it is not false, it is nothing.
// We also have symbols, but we will touch on those later in the course
// ************** Type Coercion ************************************************
// Because JavaScript is a loosely typed language, it does a funky thing called type coercion. If we combine data from different types, JavaScript tries to be helpful and make sense of the operation. This can lead to strange and unpredictable behavior and is generally best to avoid.
"2" + 2 // "22"
!3 // false
!0 // true
true * 9 // 9
false * 9 // 0