DEV Community

Cover image for 5 Quizz explained in Javascript #1
CodeOz
CodeOz

Posted on

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 this.name
  },
  getMySkills: () => this.skills,
}

console.log(myself.getName())
console.log(myself.getMySkills())
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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')
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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!

Discussion (25)

Collapse
fiddlesmic profile image
FiddleSmic

got 2/5 :,(

Collapse
luffy124 profile image
Luffy-124

3/5 !

Collapse
xvarlordx profile image
Serafim

4/5 :)
Last question makes me disappointed

Collapse
codeoz profile image
CodeOz Author

it's a good score !

Collapse
dikvega profile image
Richard Carter

4/5, thanks for this refresher and letting me know that I need to do some reading up!

Collapse
codeoz profile image
CodeOz Author

Well done! It's a great score!

Collapse
rahulydav profile image
rahul-ydav

3/5.
Thanx for 5th ques, i was unaware ....

Collapse
codeoz profile image
CodeOz Author

well done and thanks dude ! πŸ’ͺ

Collapse
someone_49 profile image
SomeOne_49

3/5

Collapse
codeoz profile image
CodeOz Author

Nice Try !

Collapse
invernomutogit profile image
Alessandro Piconi

DOH!

Collapse
coderabdullahturki profile image
Abdullah-Al-Turky

I got 3/5 :,(

Collapse
codeoz profile image
CodeOz Author

It's a great score! You will have more next time ;)

Collapse
pavelloboda profile image
Pavel Loboda

5/5 Thx. Good questions

Collapse
codeoz profile image
CodeOz Author

Nice! And thank you 😁

Collapse
tranhiepnguyenhuy1999 profile image
Huy Tran

4/5. Your article is interesting ☺️

Collapse
codeoz profile image
CodeOz Author

Well done! And thanks a lot 😁

Collapse
mitya profile image
Dima

4/5. I should repeat postfix and prefix operators.

Collapse
codeoz profile image
CodeOz Author

well done ! πŸ’ͺ

Collapse
amisandip profile image
Sandip Mukherjee

5/5

Collapse
codeoz profile image
CodeOz Author

Wow well done πŸ’ͺ

Collapse
nehalahmed profile image
Nehal Ahmed

4/5

Collapse
codeoz profile image
CodeOz Author

well done Nehal!

Collapse
agnel profile image
Agnel Waghela

4/5

Got the 1st one incorrect. Missed the connection between arrow function and this keyword.

Collapse
codeoz profile image
CodeOz Author

well done bro !