75 % of developers fail to answer these snippets

Q1. Guess the output :

let object_1 = {name:”vineet”}
let object_2 =object_1

object_1.name= “mishra”

console.log(object_2)

Take a deep breath don’t jump into the solution, think hard

Output :

{ name: ‘mishra’ }

Reason: we can see that while passing non-primitive data types, the assigned operator directly passes the address (reference). Therefore, non-primitive data types are always passed by reference.

Q2. Guess the output:

var a = 10;

var show = function() {

console.log(a)

a = 20

}

show();

Take a deep breath don’t jump into the solution, think hard

Output:
10

Reason: Hoisting Concept

Q3. Guess the Output:

console.log(name)
hello()

function hello ()
{
console.log(“say my name”)
}
var name= “vineet”;

Take a deep breath don’t jump into the solution, think hard

Output:

undefined
say my name

--

--

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
Vineet Mishra

Vineet Mishra

Full Stack Developer at CCR Tech, I write about Mobile/Web Development and Deployment, and Interview Q & A