8 Javascript quiz that may confuse you
Tags: javascript, quiz
Published: 2022-07-01 10:14:42

---
title: 8 Javascript quiz that may confuse you
published: true
date: 2022-05-02 00:00:00 UTC
tags: Javascript, quiz
canonical_url: https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/
---

Originally published on [Pitayan | 8 Javascript quiz that may confuse you](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/)

---

These days, I was preparing a small game for our team’s tech workshop. Thought it’d be a good opportunity of introducing the some fundamental and tricky stuffs around JavaScript. So I made 8 quiz to our team members. And hope they could solve them within 15 min. Eventually, it took all of them over 20 minutes to complete and most of them could solve 4-5 questions correctly.

You can take it as just a small test, each quiz has answer attached to the end of the code. Try to answer them first and then look at the answers. Good luck.

## [#](#what-do-these-console-log-print-out)What do these console.log print out?

### [#](#no-1-doctor-pavlov-has-a-dog)No. 1 – Doctor Pavlov has a dog

```js
function Animal(){ 
  this.type = "animal"
}
   
function Dog(){ 
  this.name = "dog"
}
 
Dog.prototype = new Animal()
 
var PavlovPet = new Dog(); 
 
console.log(PavlovPet. __proto__ === Dog.prototype)
console.log(Dog.prototype. __proto__ === Animal.prototype)

```

[Answer for #1](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-1-doctor-pavlov-has-a-dog)


### [#](#no-2-be-careful-with-the-sort)No. 2 – Be careful with the “sort”

```js
var arr = [5, 22, 14, 9];

console.log(arr.sort());

```

[Answer for #2](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-2-be-careful-with-the-sort)


### [#](#no-3-closure-and-event-loop)No. 3 – Closure and event loop

```js
for (var i = 0; i < 3; i++) {
  const log = () => {
    console.log(i)
  }
  setTimeout(log, 100)
}

```

[Answer for #3](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-3-closure-and-event-loop)


### [#](#no-4-there-s-indentation)No. 4 – There’s indentation

```js
function createNewArray(item) {
  return
    [item]
}
 
console.log(createNewArray(0))

```
[Answer for #4](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-4-there-s-indentation)



### [#](#no-5-what-s-inside-the-numbers)No. 5 – What’s inside the “numbers”

```js
const length = 4
const numbers = []
for (var i = 0; i < length; i++);{
  numbers.push(i + 1)
}
 
console.log(numbers)

```
[Answer for #5](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-5-what-s-inside-the-numbers)


### [#](#no-6-no-length)No. 6 – No length

```js
const clothes = ['shirt', 'socks', 'jacket', 'pants', 'hat']
clothes.length = 0
 
console.log(clothes[3])

```
[Answer for #6](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-6-no-length)


### [#](#no-7-variable-went-crazy)No. 7 – Variable went crazy

```js
var a = 1
function output () {
    console.log(a)
    var a = 2
    console.log(a)
}
console.log(a)
output()
console.log(a)

```
[Answer for #7](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-7-variable-went-crazy)


### [#](#no-8-there-s-an-accidental-declaration)No. 8 – There’s an accidental declaration

```js
function foo() {
    let a = b = 0
    a++
    return a
}
 
foo()
console.log(typeof a)
console.log(typeof b)

```
[Answer for #8](https://pitayan.com/posts/8-javascript-quiz-that-may-confuse-you/#no-8-there-s-an-accidental-declaration)


## [#](#in-the-end)In the end

Thanks so much for reading! Have you got them all correct?