CleverTap Javascript Hackathon Experience

Hope

I recently participated in a react hackathon organised by Clever-tap. I get to learn many things while I was attempting the questions. In this article I will be sharing the question I faced during the hackathon.

Q1. How can we configure the scope of the Cookie visibility?
Answer:
The Domain and Path attributes define the scope of a cookie. Read More.

Q2. What would be printed in the console?

The Correct answer for the above code is:
.

.

C) ‘0|undefined|2’

Let us see how. But before that, let’s fix the code and write it in beautiful way.

After this, I think no explanation needed.

Q3. The statement a===b refers ?
a). Both a and b are equal in value, type and reference address
b). Both a and b are equal in value and type
c). Both a and b are equal in value
d). Invalid statement
.

.

The Correct answer is b). Both a and b are equal in value and type. === Only compares value and type, It never compares reference.

Q4. What will be printed in console.

So this question checks the knowledge of scoping and priority of scoping. In the above code the priority will be given to the inner x and hence the undefined will be logged into the console.

Q5. What will be printed in console?

.

.

.

This Question is trying to check the knowledge of scoping, hoisting, IIFE, declaration of variables. In the console undefined will be printed. Because the lifespan of a and b are only inside that IIFE.

Q6. How do we insert multiline comment in JS?
Answer: /* ……. Anything */

Q7. What will be printed in the console?

So this was very interesting one. I was very confused on this one. This question was checking the knowledge in scoping, hoisting and overriding capabilities of JS.

.

.

.
So the correct answer for this is d. n n n . As in JS function declaration are hoisted, the last declaration will override the first one.

Q.8 In the switch syntax, the expression is compared with the case labels using which of the following operator(s)?

This question is trying to test the understanding about the working of switch case. This is a very interesting question. After seeing this question, I was like do I really know how switch works in JS.

Before answering above question let me share a different question:

What would be printed in console?

.

.

.
Please try the above question yourself. :)

Q.9 SYMBOLS — Which of the following are correct?

a. Symbol is derived type in JS
b. Symbol get auto-converted to string using casting
c. Symbol properties defined in an object participate in the for ..in loop
d. Symbol is used to add unique property keys to an object
.

.

.

Symbols introduced in ES6 and the main purpose of it is to provide unique property keys.
You may read more about symbols here.

Q.10 What will be printed in console?

This is a very popular and also common question these days. Almost everyone asks this.
This question check the knowledge of scoping and hoisting in JS.
.

.

.
The output of the above code will be 4,4,4,4 because once the the loop ends the value of i will be 4 and because we are using var to declare the variable, its value is captured by all instances of setTimeout and at last 4,4,4,4 will be printed.
.
Can you fix the code so that it prints 0,1,2,3
.
.
Here I am giving two ways to fix this:

Q.11 What will be printed in the console?

This question is not easy as it looks. It is checking the concept for hosting and closures.
.

.

.
The correct answer for this question is c. 10 .
.

.

.
If you know the reason how? You’re on a right path in learning JS. If not then here is the explanation:

Every function returned in for loop is creating a closure over variable i . Learn more about closure here.
And the variable i is declared using var which makes it available to whole function. And when we call the function using funcs[5]() it is returning value of i which is 10.

Q.12 What will be printed in console?

.

.

.
The correct answer is b. true false
How?

Q. 13 What is the main difference b.w. localStorage and sessionStorage?
a. lifetime
b. scope
c. both a and b
d. storage location
.

.

.

So the main difference is lifetime. Session storage got vanished as soon as user closes the browser while localStorage survives.

Q.14 What will be printed in the console?

This was my fav question among all of them. This question checks your understanding about the Event loop.
.

.

.

The correct answer is c. 1 4 3 2

How ?

The event loop checks for task in many task queues. Some task queues are Render Task Queue, Micro Task Queue and Callback Queue.

The first two console will be printed right away 1 and 4. Now the fight is b.w. setTimeout and Promise.

Promise being a micro task, will go inside micro task queue and will be executed before the callback queue. Resulting in the sequence 1 4 3 2.

After the hackathon it was clear to me that which things needs more attention. I hope these question also make you chose new things to learn.

--

--

--

A passionate iOS Developer since 2014.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Prisma vs. TypeORM

Why You Shouldn’t Nest Subscribes

Build your first Chrome Extension in 5 min

How To Check for a Substring in JavaScript

What and Whom I follow (, read, listen, and watch) to understand Micro Frontends

Dynamic Html Structure with — *ngIf, *ngFor & ngSwitch

Introduction To Redux(using React Native)

Github + CircleCI + Helm + NestJS = A special cocktail to spice up your continuous deployment

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
राहुल मिश्रा

राहुल मिश्रा

A passionate iOS Developer since 2014.

More from Medium

Setting up ESLint in JavaScript Project within run scripts— React

How to write readable JavaScript code

Special Concepts about JavaScript & MongoDB

TechMahindra React JS Hackathon Experience