Skip to content

Instantly share code, notes, and snippets.

@scastiel
Created June 12, 2017 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scastiel/29a8f0e2958e89c721e9500a00dbd30b to your computer and use it in GitHub Desktop.
Save scastiel/29a8f0e2958e89c721e9500a00dbd30b to your computer and use it in GitHub Desktop.

Quiz


Question 1

Qu'affiche le programme suivant ?

function f() {
  setTimeout(() => {
    console.log('aaa')
  }, 10)
}
console.log('bbb')
f()
console.log('ccc')

Question 2

const o = {
  a: 1,
  f() { return this.a },
  g: () => { return this.a },
  h: function() { return this.a }
}
o.f() // => ?
o.g() // => ?
o.h() // => ?

Question 3

function f() {
  return this.a
}
this.a = 1
window.a = 2
const a = 3
f() => // ?
const o = { a: 4 }
f.bind(o)() // => ?

Question 4

function f(str, obj, arr) {
  str = 'str1'
  obj.a = 'obj1'
  arr.push('arr1')
}
function g(str, obj, arr) {
  str = 'str2'
  obj = { a: 'obj2' }
  arr = ['arr2']
}
const str = 'str3'
const obj = { a: 'obj3' }
const arr = ['arr3']
f(str, obj, arr)
// str ? obj ? arr ?
g(str, obj, arr)
// str ? obj ? arr ?

Question 5

function f(a, b, c) {
  console.log(a)
  console.log(b)
  console.log(c)
}
f.apply(null, [1, 2, 3]) // => ?
f.call(null, [1, 2, 3]) // => ?

Question 6

Écrire les fonctions a et b telles que le programme suivant renvoie [20, 40, 60, 80] :

function a(/* ... */) { /* ... */ }
function b(/* ... */) { /* ... */ }
[1, 2, 3, 4, 5, 6, 7, 8, 9]
  .filter(a)
  .map(b)

Question 7

Écrire la fonction a telle que le programme suivant renvoie { a: 1, b: 2, c: 3 }.

const arr = [['a', 1], ['b', 2], ['c', 3]]
function a(/* ... */) { /* ... */ }
arr.reduce(a, {})

Question 8

Que renvoient les lignes suivantes ?

0 == '0'
0 == undefined
0 == null
0 == false
0 == []
false == []

Qu'en tirez-vous comme conclusion ?


Question 9

Que renvoient les lignes suivantes ?

0.6 + 0.3 === 0.9
12 / 0
12 / 0 - 12 / 0
-12 / (12 / 0)
12 + '5'
12 - '5'
12 - 'a'

Question 10

Qu'affiche le programme suivant ?

function f(value) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (value !== 0) {
        resolve(value * 10)
      } else {
        reject(new Error('Value must not be 0'))
      }
    }, value)
  })
}
[3, 4, 0, 2, 1].forEach(value => {
  f(value)
    .then(res => console.log(res))
    .catch(err => console.error(err))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment