JS Flashcards

1
Q

ECMAScript

A

JavaScript standard

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ES12

A

ECMAScript 2021

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Babel

A

Transpiles JS code between versions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Node.js

A

JavaScript runtime environment based on Google’s Chrome V8 JavaScript engine
Run a JS file: node name_of_file.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

const vs let

A

const defined variables can’t be reassigned. If an array (object), the content of array can be changed
let defined variable can be reassigned a new value.

use const as a starting point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

array forEach

A

const t = [1, -1, 3]

t.push(5)

console. log(t.length) // 4 is printed
console. log(t[1]) // -1 is printed

t.forEach(value => {
console.log(value) // numbers 1, -1, 3, 5 are printed, each to own line
})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

array in immutable way (functional)

A

const t = [1, -1, 3]

const t2 = t.concat(5) // creates an new array; does not change the original array

console. log(t) // [1, -1, 3] is printed
console. log(t2) // [1, -1, 3, 5] is printed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

array map

A

const t = [1, 2, 3]

const m1 = t.map(value => value * 2)
console.log(m1)   // [2, 4, 6] is printed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

destructuring assignment

A

const t = [1, 2, 3, 4, 5]

const [first, second, …rest] = t

console. log(first, second) // 1, 2 is printed
console. log(rest) // [3, 4, 5] is printed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

object literal

A

One way of defining objects in JS listing its properties within braces.

const object1 = {
  name: 'Arto Hellas',
  age: 35,
  education: 'PhD',
}
const object2 = {
  name: 'Full Stack web application development',
  level: 'intermediate studies',
  size: 5,
}
const object3 = {
  name: {
    first: 'Dan',
    last: 'Abramov',
  },
  grades: [2, 3, 5, 3],
  department: 'Stanford University',
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

referencing object property

A

“dot” notation or brackets

console.log(object1.name)         // Arto Hellas is printed
const fieldName = 'age' 
console.log(object1[fieldName])    // 35 is printed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

add properties to an object

A

object1.address = ‘Helsinki’
object1[‘secret number’] = 12341

The latter of the additions has to be done by using brackets, because when using dot notation, secret number is not a valid property name because of the space character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Arrow function (complete)

A
(p1, p2) => {
  console.log(p1)
  console.log(p2)
  return p1 + p2
}
// assign the function to a variable 
const sum = (p1, p2) => {
  console.log(p1)
  console.log(p2)
  return p1 + p2
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Arrow function (single parameter)

A
// exclude the parentheses
const square = p => {
  console.log(p)
  return p * p
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Arrow function (single expression)

A
// exclude braces
const square = p => p * p
// commonly used in map 
const t = [1, 2, 3]
const tSquared = t.map(p => p * p)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

function key word (function declaration)

A
function product(a, b) {
    return a * b
}

const result = product(2, 6)

17
Q

function key word (function expression)

A

// assign function expression to variable

const average = function(a, b) {
    return (a + b) / 2
}

const result = average(2, 5)