Skip to content

Repo contains basic & famous interview questions in javascript

Notifications You must be signed in to change notification settings

gokulkrishh/js-interview-questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Javascript Interview Questions

Repo contains basic & famous interview questions in javascript

Table of Contents

  1. Global & Local Variables
  2. Hoisting
  3. Operators
  4. Closures
  5. Arrays
  6. Objects
  7. Prototype

Global and Local Variables

  • What is the output of the below program and why ?
var foo = 10;

function myFunz() {
  foo = 11;
  console.log(foo); //print
}

console.log(foo); //print

myFunz();

console.log(foo); //print

Hoisting

  • What is the output of the below program and why ?
myFunz(); //Will this function execute if yes, what is the output or if no why ?

function myFunz() {
  console.log(bar); //print
  var bar = 11;
  console.log(bar); //print
}

Operators

  • What will be output of below program and why ?
console.log(0 == 1);

console.log(0 == "0");

console.log(0 === "0");

console.log(true == 1);

console.log(false == 0);

console.log(1 + 2 + "3");

console.log(1 + "2" + "3");

console.log("1" + 2);

console.log("1" + "3" + 2);

⬆ back to top

Closures

  • What is the output of the below program and why ?
function parent(foo, bar) {
  var x = foo;

  function child() {
    console.log(x); //print
    console.log(foo); //print
    console.log(bar); //print
  }

  console.log(x); //print

  child();
}

parent();
  • Fix the below program to print values from 0 to 9
for (var i = 0; i < 9; i++) {
  setTimeout(function () {
    console.log(); //Should print from 0 to 9
  }, 0);
}

⬆ back to top

Arrays

  • How will you tell below input in the function is array or not ?
function myFunz(x, y) {
  //write a method to find given input is array or not
  //If not array, print x & y type as well
}

var arr = [1, 2, 3];

var obj = {
  name: "gokul",
  age: 24
};

myFunz(arr, obj);
  • Find max and min value in an array ?

  • Write a program to remove duplicate value in an array

  • Write a program to search an element in an array and optimize it to the most efficient solution and explain its complexity

⬆ back to top

Objects

  • Write a function to do deep copy of the given object

  • Write a function to compare two objects

Prototype

  • Write a class in javascript and its properties and methods should be inheritable by other functions

  • How will you extend a method in javascript ?

⬆ back to top

Contributions

If you find an issue, please file it. PR's are most welcome ;)

About

Repo contains basic & famous interview questions in javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages