1 of 234

A specific introduction to JavaScript

For the Trial By Fire Tutorial - By Joshua Levin

2 of 234

This is a slice

3 of 234

What is JavaScript?

  • The language that powers most of the internet
  • Can be used in everything from websites, servers, games and desktop applications - such as GDevelop!
  • Is sometimes its own enemy - https://www.youtube.com/watch?v=et8xNAc2ic8

4 of 234

What is a variable?

5 of 234

What is a variable?

meaning_of_life = 42

moon = “full”

6 of 234

What is a variable?

meaning_of_life

7 of 234

What is a variable?

moon

8 of 234

What is a variable?

“Something we use to hold information”

9 of 234

What is a variable?

“Something we use to hold a value”

10 of 234

What is a variable?

meaning_of_life = 42

moon = “full”

11 of 234

What is a variable?

meaning_of_life = 42

moon = “full”

12 of 234

What is a variable?

meaning_of_life = 42

moon = “full”

13 of 234

What is assignment?

14 of 234

What is assignment?

“This has the value of that”

15 of 234

What is assignment?

=

16 of 234

What is assignment?

meaning_of_life = 42

moon = “full”

17 of 234

What is assignment?

meaning_of_life = 42

moon = “full”

18 of 234

What are the types of variables?

19 of 234

What are the types of variables?

“Can this variable change?”

20 of 234

What are the types of variables?

“After I give this variable a value, can it have a different value?”

21 of 234

What are the types of variables?

let meaning_of_life = 42

const moon = “full”

22 of 234

What are the types of variables?

let meaning_of_life = 42

const moon = “full”

23 of 234

What are the types of variables?

const

24 of 234

What are the types of variables?

const(ant)

25 of 234

What are the types of variables?

const

26 of 234

What are the types of variables?

const:

“This variable can never change”

27 of 234

What are the types of variables?

const moon = “full”

28 of 234

What are the types of variables?

const moon = “full”

moon = “new”

29 of 234

What are the types of variables?

const moon = “full”

moon = “new”

30 of 234

What are the types of variables?

let

31 of 234

What are the types of variables?

let:

“This variable can be changed”

32 of 234

What are the types of variables?

let meaning_of_life = 42

33 of 234

What are the types of variables?

let meaning_of_life = 42

meaning_of_life = “who knows?”

34 of 234

What are the types of variables?

let meaning_of_life = 42

meaning_of_life = “who knows?”

35 of 234

What are the types of variables?

let meaning_of_life = 42

const moon = “full”

36 of 234

Which one should I use?

const

let

37 of 234

Which one should I use?

const

let

38 of 234

What are the types of variables?

“var”

39 of 234

What are the types of variables?

“var”

40 of 234

What is comparing?

41 of 234

What is comparing?

“Is that variable this value?”

42 of 234

What is comparing?

“Is that variable this value?”

Answer: true or false

43 of 234

What is comparing?

“Is that variable this value?”

Answer: true or false

(boolean)

44 of 234

What is comparing?

“Is the meaning of life 42?”

45 of 234

What is comparing?

“Is the meaning of life 42?”

meaning_of_life === 42

46 of 234

What is comparing?

===

47 of 234

What is comparing?

=

48 of 234

What is comparing?

=

(assignment)

49 of 234

What is comparing?

==

50 of 234

What is comparing?

==

(don’t use it)

51 of 234

What is comparing?

===

52 of 234

What is comparing?

if the meaning of life is 42

do something cool...

53 of 234

What is comparing?

if ( ) { }

54 of 234

What is comparing?

if ([comparison]) { }

55 of 234

What is comparing?

if ([comparison]) {

[action]

}

56 of 234

What is comparing?

if (this is true) {

[action]

}

57 of 234

What is comparing?

if (this is true) {

do this

}

58 of 234

What is comparing?

if the meaning of life is 42

do something cool...

59 of 234

What is comparing?

if( the meaning of life is 42)

do something cool...

60 of 234

What is comparing?

if( the meaning of life is 42) {}

do something cool...

61 of 234

What is comparing?

if( the meaning of life is 42) {

do something cool…

}

62 of 234

What is comparing?

if( the meaning of life is 42) {

do something cool…

}

63 of 234

What is comparing?

if( the meaning of life is 42) {

do something cool…

}

64 of 234

What is comparing?

if( the meaning of life is 42) {

do something cool…

}

65 of 234

What is comparing?

if(meaning_of_life is 42) {

do something cool…

}

66 of 234

What is comparing?

if(meaning_of_life === 42) {

do something cool…

}

67 of 234

What is comparing?

if(meaning_of_life === 42) {

// do something cool…

}

68 of 234

What is a comment?

//

69 of 234

What is a comment?

//

(note to someone reading)

70 of 234

What is a comment?

//

(note to someone reading)

(computer doesn’t use it)

71 of 234

What is comparing?

if(meaning_of_life === 42) {

// do something cool…

}

72 of 234

What is comparing?

if(meaning_of_life === 42) {

// do something cool…

}

73 of 234

What is comparing?

if(meaning_of_life === 42) {

// do something cool…

}

74 of 234

What is JSON?

  • JavaScript Object Notation
  • A very popular data storage format that is deeply integrated with JavaScript
  • Looks pretty crazy but it will make sense fast

75 of 234

JSON is limited

  • Object
  • Array
  • Number
  • String
  • Boolean
  • Null

76 of 234

NULL

77 of 234

NULL

(Literally

Nothing)

78 of 234

Boolean

True / False

79 of 234

String

“Some text”

80 of 234

String

‘Some text’

81 of 234

String

`Some text`

82 of 234

String

“Some text”

83 of 234

Number

1

84 of 234

Number

100

85 of 234

Number

42

86 of 234

Array

[ ]

87 of 234

Array

88 of 234

Array

89 of 234

Array

Length

4

90 of 234

Array

Length

4

0

91 of 234

Array

Length

4

0

1

92 of 234

Array

Length

4

0

1

2

93 of 234

Array

Length

4

0

1

2

3

94 of 234

Array

Length

4

0

1

2

3

“Index”

95 of 234

Array

Length

4

0

1

2

3

First = 0

96 of 234

Array

Length

4

0

1

2

3

Last = Length - 1

97 of 234

Array

0

1

2

3

98 of 234

Array

0

1

2

3

“Store moon at index 2”

99 of 234

Array

0

1

2

3

“Store moon at index 2”

100 of 234

Array

0

1

2

3

“Store moon at index 2”

101 of 234

Array

0

1

2

3

102 of 234

Array

0

1

2

3

“Get me what’s in index 2”

103 of 234

Array

0

1

2

3

“Get me what’s in index 2”

104 of 234

Array

0

1

2

3

“Get me what’s in index 2”

105 of 234

Array

0

1

2

3

106 of 234

Array

0

1

2

3

“Get me what’s in index 0”

107 of 234

Array

0

1

2

3

“Get me what’s in index 0”

108 of 234

Array

0

1

2

3

“Get me what’s in index 0”

109 of 234

Array

0

1

2

3

“Get me what’s in index 0”

UNDEFINED

110 of 234

Array

0

1

2

3

111 of 234

Array

0

1

2

3

“Get me what’s in index 4”

112 of 234

Array

0

1

2

3

“Get me what’s in index 4”

UNDEFINED

113 of 234

Array

0

1

2

3

114 of 234

Array

0

1

2

3

“Store car in index 2”

115 of 234

Array

0

1

2

3

“Store car in index 2”

116 of 234

Array

0

1

2

3

“Store car in index 2”

117 of 234

Let’s code it up - Arrays

[ ]

118 of 234

Let’s code it up - Arrays

Initializing

const

119 of 234

Let’s code it up - Arrays

Initializing

const box

120 of 234

Let’s code it up - Arrays

Initializing

const box =

121 of 234

Let’s code it up - Arrays

Initializing

const box = []

122 of 234

Let’s code it up - Arrays

Initializing

const box = []

box=[]

123 of 234

Let’s code it up - Arrays

Inserting

const box = []

124 of 234

Let’s code it up - Arrays

Inserting

const box = []

box

125 of 234

Let’s code it up - Arrays

Inserting

const box = []

box[]

126 of 234

Let’s code it up - Arrays

Inserting

const box = []

box[0]

127 of 234

Let’s code it up - Arrays

Inserting

const box = []

box[0] =

128 of 234

Let’s code it up - Arrays

Inserting

const box = []

box[0] = moon

129 of 234

Let’s code it up - Arrays

Inserting

const box = []

box[0] = moon

box=[moon]

130 of 234

Let’s code it up - Arrays

Inserting

const box = [moon]

131 of 234

Let’s code it up - Arrays

Inserting

const box = [moon]

box[]

132 of 234

Let’s code it up - Arrays

Inserting

const box = [moon]

box[1]

133 of 234

Let’s code it up - Arrays

Inserting

const box = [moon]

box[1] =

134 of 234

Let’s code it up - Arrays

Inserting

const box = [moon]

box[1] = car

135 of 234

Let’s code it up - Arrays

Inserting

const box = [moon]

box[1] = car

box=[moon,car]

136 of 234

Let’s code it up - Arrays

Replacing

const box = [moon,car]

137 of 234

Let’s code it up - Arrays

Replacing

const box = [moon,car]

box[]

138 of 234

Let’s code it up - Arrays

Replacing

const box = [moon,car]

box[0]

139 of 234

Let’s code it up - Arrays

Replacing

const box = [moon,car]

box[0] =

140 of 234

Let’s code it up - Arrays

Replacing

const box = [moon,car]

box[0] = cake

141 of 234

Let’s code it up - Arrays

Replacing

const box = [moon,car]

box[0] = cake

box=[cake,car]

142 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

143 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const first

144 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const first =

145 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const first = box

146 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const first = box[]

147 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const first = box[0]

148 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const first = box[0]

first=cake

149 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

150 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const last

151 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const last =

152 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const last = box[]

153 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const last = box[]�

last index is length - 1

154 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const

const last = box[]

155 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index

const last = box[]

156 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index =

const last = box[]

157 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box

const last = box[]

158 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.

const last = box[]

159 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.length

const last = box[]

160 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.length -

const last = box[]

161 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.length - 1

const last = box[]

162 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.length - 1

const last = box[index]

163 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const last = box[box.length - 1]

164 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.length - 1

const last = box[index]

165 of 234

Let’s code it up - Arrays

Retrieving

const box = [cake,car]

const index = box.length - 1

const last = box[index]

last=car

166 of 234

Object

{ }

167 of 234

Object

{ } =

168 of 234

Object

{ } =

169 of 234

Object

{ } =

170 of 234

Object

{ } =

171 of 234

Object

{ } =

172 of 234

Object

{ } =

173 of 234

Object

{ } =

174 of 234

Object

{ }

This bad boy can fit so many properties in it

175 of 234

“Property”?

176 of 234

Property

Name = Thing

177 of 234

Property

Name = Thing

Key = Value

178 of 234

Property

Name = Thing

Key = Value

“key”:value

179 of 234

Property

“Car” =

180 of 234

Property

“Moon” =

181 of 234

Object

182 of 234

Object

“Store this as Moon”

183 of 234

Object

MOON

“Store this as Moon”

184 of 234

Object

MOON

“Store this as Moon”

185 of 234

Object

MOON

“Get me Moon”

186 of 234

Object

“Get me Moon”

MOON

187 of 234

Object

MOON

188 of 234

Object

MOON

“Get me Car”

189 of 234

Object

MOON

“Get me Car”

190 of 234

Object

MOON

“Get me Car”

UNDEFINED

191 of 234

Object

MOON

192 of 234

Object

MOON

“Replace

Moon with

this”

193 of 234

Object

MOON

“Replace

Moon with

this”

194 of 234

Object

MOON

“Replace

Moon with

this”

195 of 234

Object

MOON

“Replace

Moon with

this”

196 of 234

Object

MOON

“Replace

Moon with

this”

197 of 234

Let’s code it up - Objects

{ }

198 of 234

Let’s code it up - Objects

Initializing

const

199 of 234

Let’s code it up - Objects

Initializing

const bucket

200 of 234

Let’s code it up - Objects

Initializing

const bucket =

201 of 234

Let’s code it up - Objects

Initializing

const bucket = {}

202 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

203 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

bucket

204 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

bucket[]

205 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

bucket[“moon”]

206 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

bucket[“moon”] =

207 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

bucket[“moon”] = moon

208 of 234

Let’s code it up - Objects

Inserting

const bucket = {}

bucket[“moon”] = moon

bucket={“moon”:moon}

209 of 234

Let’s code it up - Objects

Inserting

const bucket = {“moon”:moon}

210 of 234

Let’s code it up - Objects

Inserting

const bucket = {“moon”:moon}

bucket[“car”] = car

211 of 234

Let’s code it up - Objects

Inserting

const bucket = {“moon”:moon}

bucket[“car”] = car

bucket={“car”:car}

212 of 234

Let’s code it up - Objects

Replacing

const bucket = {“moon”:moon, “car”:car}

213 of 234

Let’s code it up - Objects

Replacing

const bucket = {

“moon”:moon,

“car”:car

}

214 of 234

Let’s code it up - Objects

Replacing

const bucket = {

“moon”:moon,

“car”:car

}

bucket[“moon”] = cake

215 of 234

Let’s code it up - Objects

Replacing

const bucket = { const bucket = {

“moon”:moon, “moon”:cake,

“car”:car “car”:car

} }

bucket[“moon”] = cake

216 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

217 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first

218 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first =

219 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first = bucket

220 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first = bucket[]

221 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first = bucket[“moon”]

222 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first = bucket.moon

223 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first = bucket[“moon”]

224 of 234

Let’s code it up - Objects

Retrieving

const bucket = {

“moon”:cake,

“car”:car

}

const first = bucket[“moon”] first=cake

225 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

226 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

227 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

228 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

229 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

230 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

231 of 234

JSON example

  • Object - { }
  • Array - [ ]
  • Number - 101
  • String - “written text”
  • Boolean - true or false
  • Null - literally nothing

232 of 234

Arrays have some useful build-in tools

For each bucket in the array, do something to whatever is inside

Array.forEach( (value) => {

// do something with value

})

233 of 234

Arrays have some useful build-in tools

Go through each bucket and give me a new array only with buckets that match my criteria

var filteredArray = Array.filter( (value) => {

// If our value matches some criteria� return true � // Otherwise� return false

})

234 of 234

fin