DEV Community

Jyoti Jingar
Jyoti Jingar

Posted on

Javascript Interview Logic Question

Predict the output:

console.log("20" - 5 + "10");
Enter fullscreen mode Exit fullscreen mode

What is the final output?

var a = "10";
var b = 5;
console.log(a * b + a);
Enter fullscreen mode Exit fullscreen mode

Identify the error (if any):

const a = 10;
{
  const a = 20;
  console.log(a);
}
console.log(a);
Enter fullscreen mode Exit fullscreen mode

What kind of error will occur?

const x;
x = 100;
Enter fullscreen mode Exit fullscreen mode

What will happen?

console.log(b);
var b = 10;
Enter fullscreen mode Exit fullscreen mode

Write logic to swap two numbers

Predict the output

var x = "10";
var x = 10;
console.log(x + 5);
Enter fullscreen mode Exit fullscreen mode

What will be printed?

var a = 5;
if (true) {
  var a = 10;
}
console.log(a);
Enter fullscreen mode Exit fullscreen mode

Will this code run successfully? If yes, what is the output?

var a;
console.log(a);
a = 100;
Enter fullscreen mode Exit fullscreen mode

Write logic to calculate the sum of four numbers using currying.

What is the main difference in return value between forEach and map?

What is the difference in iteration behavior between a normal loop and a for…in loop when an array has missing elements?

Write a program to find the sum of all array elements using reduce.

Write a program to check whether a value exists in an array.

What will be printed?

const arr = [12, "12", 15];
const result = arr.filter((ele) => ele === 12);
console.log(result);
Enter fullscreen mode Exit fullscreen mode

Which loop skips empty elements and why?

const arr = [ , 2, , 4];

Enter fullscreen mode Exit fullscreen mode

How can object values be accessed

What will be the output?

const user = {
  name: "A",
  age: 25,
  age : 32
};
console.log(user.age);

Enter fullscreen mode Exit fullscreen mode

What will be the output?

const obj = {
  info: {
    city: "Ahmedabad"
  }
};
console.log(obj.info2);

Enter fullscreen mode Exit fullscreen mode

What will be the output, if any error then how do handle it?

const obj = {
  info: {
    city: "Ahmedabad"
  }
};
console.log(obj.info2.city);

Enter fullscreen mode Exit fullscreen mode

What will be the output?

const obj = {
  id: 10,
  show: () => {
    return this.id;
  }
};
console.log(obj.show());

Enter fullscreen mode Exit fullscreen mode

Write a program to add new properties to an object.

What will be the output?

localStorage.setItem("count", 10);
localStorage.setItem("count", 20);
console.log(localStorage.getItem("count"));

Enter fullscreen mode Exit fullscreen mode

What will be the output? If any error then how to handle it

localStorage.setItem("user", { name: "A" });
console.log(localStorage.getItem("user"));

Enter fullscreen mode Exit fullscreen mode

What will be the output?

console.log("start");
setTimeout(() => {
  console.log("timeout");
}, 0);
console.log("end");

Enter fullscreen mode Exit fullscreen mode

what is API and to write a API Method with syntax

Top comments (0)