5 Quizz explained in Javascript #1

Welcome to the first javascript quizz!

You can answer to the question and check the response with the explication!

Good luck!

1

const myself = {
name: ‘code__oz’,
skills: [‘js’, ‘ts’, ‘vuejs’, ‘nodejs’],
getName() {
return th…


This content originally appeared on DEV Community and was authored by CodeOz

Welcome to the first javascript quizz!

You can answer to the question and check the response with the explication!

Good luck!

1

const myself = {
  name: 'code__oz',
  skills: ['js', 'ts', 'vuejs', 'nodejs'],
  getName() {
    return this.name
  },
  getMySkills: () => this.skills,
}

console.log(myself.getName())
console.log(myself.getMySkills())

What is the output? 👇

  • A) code__oz and ['js', 'ts', 'vuejs', 'nodejs']
  • B) undefined and undefined
  • C) code__oz and undefined
  • D) undefined and ['js', 'ts', 'vuejs', 'nodejs']

.
..
...
....
.....
......
.......
.......

C → We have undefined value since we are using arrow function and this in the same context, so the this keyword refers to its current surrounding scope, unlike regular functions! In a browser context, this refer to window object!

2

let toto = { message: 'Hello' }
let tutu

tutu = toto
toto.message = 'Bye'
console.log(tutu.message)

What is the output? 👇

  • A) undefined
  • B) Bye
  • C) Hello
  • D) ReferenceError

.
..
...
....
.....
......
.......
.......

B → In JavaScript, all objects interact by reference when setting them equal to each other. So in this example toto and tutu share the same reference so if you change value from one, you will change the shared reference and you will indirectly change the value of the other variable.

3

let number = 0
console.log(number++)
console.log(++number)
console.log(number)

What is the output? 👇

  • A) 1 1 2
  • B) 1 2 2
  • C) 0 1 2
  • D) 0 2 2

.
..
...
....
.....
......
.......
.......

D -> The postfix unary operator ++:

  1. Returns the value (this returns 0)
  2. Increments the value (number is now 1)

The prefix unary operator ++:

  1. Increments the value (number is now 2)
  2. Returns the value (this returns 2)

This returns 0 2 2.

4

function sum(a, b) {
  return a + b
}

sum(2, '5')

What is the output? 👇

  • A) TypeError
  • B) NaN
  • C) "25"
  • D) 7

.
..
...
....
.....
......
.......
.......

C → JavaScript converts the number 2 into a string. It's because during the addition of a numeric type (2) and a string type ('5'), the number is treated like a string ! So we have '2' + '5' → '25'

5

setInterval(() => console.log('Hey !'), 5000)

What does the setInterval method return in the browser? 👇

  • A) a unique id
  • B) the amount of milliseconds specified
  • C) the passed function
  • D) undefined

What is the output? 👇

.
..
...
....
.....
......
.......
.......

A -> It returns a unique id. This id can be used to clear that interval with the clearInterval() function.

Tell me your score in comment! 👨‍🏫

I hope you like this reading!

🎁 You can get my new book Underrated skills in javascript, make the difference for FREE if you follow me on Twitter and MP me 😁

Or get it HERE

🎁 MY NEWSLETTER

☕️ You can SUPPORT MY WORKS 🙏

🏃‍♂️ You can follow me on 👇

🕊 Twitter : https://twitter.com/code__oz

👨‍💻 Github: https://github.com/Code-Oz

And you can mark 🔖 this article!


This content originally appeared on DEV Community and was authored by CodeOz


Print Share Comment Cite Upload Translate Updates
APA

CodeOz | Sciencx (2021-10-07T14:58:21+00:00) 5 Quizz explained in Javascript #1. Retrieved from https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/

MLA
" » 5 Quizz explained in Javascript #1." CodeOz | Sciencx - Thursday October 7, 2021, https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/
HARVARD
CodeOz | Sciencx Thursday October 7, 2021 » 5 Quizz explained in Javascript #1., viewed ,<https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/>
VANCOUVER
CodeOz | Sciencx - » 5 Quizz explained in Javascript #1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/
CHICAGO
" » 5 Quizz explained in Javascript #1." CodeOz | Sciencx - Accessed . https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/
IEEE
" » 5 Quizz explained in Javascript #1." CodeOz | Sciencx [Online]. Available: https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/. [Accessed: ]
rf:citation
» 5 Quizz explained in Javascript #1 | CodeOz | Sciencx | https://www.scien.cx/2021/10/07/5-quizz-explained-in-javascript-1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.