9

Ultimate List of JavaScript Interview Questions. 90 questions with answers

 4 years ago
source link: https://blog.soshace.com/ultimate-list-of-javascript-interview-questions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

JavaScript Question № 1 Practical for Senior

How to compare two objects with nested properties in JavaScript?

JavaScript Question № 2 Theoretical for Middle

List special numeric values.

JavaScript Question № 3 Theoretical for Senior

Explain the Map , Set , WeakMap and WeakSet .

JavaScript Question № 4 Theoretical for Middle

List the methods to search in an array.

JavaScript Question № 5 Theoretical for Middle

What is the purpose of the file package - lock . json ?

JavaScript Question № 6 Theoretical for Junior

What’s the difference between using var , let , and const ?

JavaScript Question № 7 Theoretical for Middle

What is Cross-Origin Requests and CDN?

JavaScript Question № 8 Practical for Middle

Does it make sense to add directive use strict in modern scripts?

JavaScript Question № 9 Theoretical for Middle

What are web workers?

JavaScript Question № 10 Practical for Middle

Improve the code using ES6

//sample
let person = {
  name: 'Anna',
  age: 56,
  job: {
    company: 'Tesco',
    title: 'Manager'
  }
};
function getInfo(person) {
  var age = person.age,
    yearOfBirth = 2018 - age,
    name = person.name,
    company = person.job.company;
  console.log(`${ name } works at ${ company } and was born in ${ yearOfBirth }.`);
}

JavaScript Question № 11 Practical for Middle

Write an example of testing the sum function.

JavaScript Question № 12 Theoretical for Junior

How to show the user a notification that javascript is not enabled by his browser?

JavaScript Question № 13 Practical for Senior

Give webpack config sample for scss using.

JavaScript Question № 14 Theoretical for Junior

Why is the order of adding scripts to the page important?

JavaScript Question № 15 Practical for Senior

Create a script to lazy load the images shown after scrolling.

JavaScript Question № 16 Theoretical for Junior

How to get the current URL?

JavaScript Question № 17 Practical for Middle

Write a builder class to create developer instances.

//Sample
const developer = new DeveloperBuilder('John')
  .addSkill('ES6')
  .addSkill('TypeScript')
  .setFramework('React');

JavaScript Question № 18 Practical for Senior

Create a rectangle object with a private width and public height using the Revealing Module Pattern.

JavaScript Question № 19 Practical for Senior

Create a function that will receive an estimate as the input and output the average of all previously obtained estimates.

// add the code here
setRate(5); // 5
setRate(3); // 4
setRate(4); // 4
setRate(0); // 3

JavaScript Question № 20 Practical for Senior

Write Observer pattern sample.

JavaScript Question № 21 Practical for Middle

Improve the code using classes.

//Sample
 
function Person(name, lastName) {
  this.name = name;
  this.lastName = lastName;
}
 
Person.prototype.getFullName = function() {
  return this.name + " " + this.lastName;
};
 
function Developer(skills, name, lastName) {
  this._super.call(this, name, lastName);
  this.skills = skills;
}
 
Developer.prototype = Object.create(Person.prototype);
Developer.prototype.constructor = Developer;
Developer.prototype._super = Person;
 
Developer.prototype.getDeveloperInfo = function() {
  return this.name + " " + this.lastName + ", skills: " + this.skills;
};
 
var developer = new Developer("JavaScript, React, Redux", "John", "Doe");
console.log(developer.getFullName());
console.log(developer.getDeveloperInfo());

JavaScript Question № 22 Practical for Middle

What is output?

i = 10;
var j = 1;
for(var i=1; i < 5; i++) {
  j++;
}
console.log(i);
console.log(j++);

JavaScript Question № 23 Practical for Senior

How to get the sum of even numbers if the sum of array elements is even and the sum of odd numbers if the sum of array elements is odd? Complete the function without using additional variables.

// store sum, evenSum and evenFlag
// create an example
 
function getOddOrEvenSum(arr) {
  var a = 0;
  var b = 0;
 
  arr.forEach(function(number) {
    // place for code
  });
  // place for code
}
 
var arr = [1, 2, 3, 4, 5, 10, 11];
console.log(getOddOrEvenSum(arr))

JavaScript Question № 24 Practical for Middle

Write a function to find the sum number of array elements using reduce.

const arr = [11, 29, 5]

JavaScript Question № 25 Practical for Middle

Write a JavaScript function to check that two words are anagrams (formed by rearranging the letters of another)

JavaScript Question № 26 Practical

How to add your method to the Array object so the following code would work?

var arr = [1, 2, 3, 4, 5];
var sum = arr.sum();
console.log(sum)

JavaScript Question № 27 Practical for Junior

How to check that variable is not undefined? How to check that a property exists in an object?

JavaScript Question № 28 Practical for Senior

What is wrong with this code?

// example with parameters in which strict comparison is important
 
function checkTheYear(initYear, targetYear) {
 switch(targetYear) {
   case initYear - 30:
     console.log('I\'m sure in 1985, plutonium is available at every corner drugstore, but in 1955 it\'s a little hard to come by.');
     return true;
    case initYear - 100:
     console.log('A hundred years ago? But that\'s now!');
     return true;
    case initYear + 30:
     console.log('Nobody calls me chicken!')
            return true;
    default:
     console.log('Time traveling is just too dangerous. Better that I devote myself to study the other great mystery of the universe: women!');
     return false;
  }
}
 
function backToTheFuture(targetYear) {
  var timeMachine = {
    model: 'DeLorean DMC-12',
    initYear: '1985'
  }
  if(checkTheYear(timeMachine.initYear, targetYear)) {
   // execute the secret code for time travel to the targetYear
  }
}

JavaScript Question № 29 Practical for Middle

Write 3 code examples to check whether a string “Soshace” contains a substring “sh”.

let string = "Soshace", substring = "sh"

JavaScript Question № 30 Theoretical for Senior

How to forbid adding, removing and changing of object properties?

JavaScript Question № 31 Practical for Middle

How to update the sample to use previous object constructor?

function Developer(experience) {
  this.experience = experience;
}
Developer.prototype = {
  skills: ['JavaScript']
};
 
let senior = new Developer(7);
let junior = new senior.constructor(1);
 
console.log( junior.experience ); // undefined

JavaScript Question № 32 Practical for Senior

Write a recursive function to create a deep copy of the object

JavaScript Question № 33 Practical for Middle

Give code samples for immutable operations using Object . assign and Spread operator

JavaScript Question № 34 Practical for Middle

Update the code to correctly release the button object by the garbage collector.

<button id="click-me" class="btn">Click Me</button>
<script type="text/javascript">
var elements = {
    button: document.getElementById('click-me'),
};
elements.button.onclick = function() {
    alert('clicked!');
    document.body.removeChild(elements.button);
}
</script>

JavaScript Question № 35 Practical for Junior

Write a simple function to check that a number is an integer?

JavaScript Question № 36 Practical for Senior

Optimize the function using switch statement.

function getFullPrice(type) {
    var ticket = 10,
    luggage = 7,
    service = 5,
    taxes = 3,
    price = 0;
 
    switch(type) {
        case 'ticket':
     price = ticket;
     break;
        case 'luggage':
     price = ticket + luggage;
     break;
        case 'service':
     price = ticket + luggage + service;
     break;
  }
  
  price += taxes;
  
  return price;
}
console.log(getFullPrice('ticket'));
console.log(getFullPrice('luggage'));
console.log(getFullPrice('service'));

JavaScript Question № 37 Practical for Senior

Provide some shorthand coding techniques using operators “&&” , | | and ?

JavaScript Question № 38 Theoretical for Junior

How to stop the setInterval function?

JavaScript Question № 39 Theoretical for Middle

Explain the output of the code? How to improve this code?

console.log(1.1 - 0.2)
// console output
0.9000000000000001

JavaScript Question № 40 Theoretical for Junior

What is the difference between the following examples of creating a function?

function myFunc() {
  // some logic
}
and
var myFunc = function() {
 // some logic
}

JavaScript Question № 41 Practical for Senior

Write a JavaScript function that accepts a number as a parameter and check the number is prime or not.

Note: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

JavaScript Question № 42 Practical for Senior

Write a JavaScript program to find the greatest common divisor of two positive numbers.

Sample Input: 32 , 24

Sample Output: 8

JavaScript Question № 43 Theoretical for Middle

What is a hasOwnProperty ?

JavaScript Question № 44 Theoretical for Senior

Explain the Symbol type.

JavaScript Question № 45 Theoretical for Senior

What are accessor descriptors?

JavaScript Question № 46 Practical for Middle

Correct the code without changing the object sample.

Sample

let user = {
  name: "John",
  logName() {
    console.log(`My name is ${this.name}!`);
  }
};
 
setTimeout(user.logName, 1000);

JavaScript Question № 47 Theoretical for Senior

What is the difference between Boolean (true) and new Boolean (true) ?

JavaScript Question № 48 Practical for Junior

Write a JavaScript program to create a Clock

Sample Output (will come every second):

09 : 57 : 12

09 : 57 : 13

09 : 57 : 14

JavaScript Question № 49 Theoretical for Senior

Categorize JavaScript test tools by type.

JavaScript Question № 50 Practical for Middle

How to remove elements from an array by criteria? Complete the function.

// using loop and splice

// create an example

Sample

function removeElements(arr, criteriaFunc) {
  var i;
  for (i = 0; i < arr.length; i++) {
    if (criteriaFunc(arr[i])) {
      // place for code
    }
  }
  return arr;
}
 
console.log(removeElements([1, 2, 5, 4, 6, 7, 3, 1, 5], function(number) {
  return number < 5;
}));

JavaScript Question № 51 Practical for Middle

Write a JavaScript program to find the most frequent item of an array.

Sample Input: [d,3,a,d,d,c,c,3,1,a,d]

Sample Output : d : 4

JavaScript Question № 52 Practical for Middle

Write a JavaScript program to remove duplicate items from the char array.

Sample Input: [d,3,a,d,d,c,c,3,1,a,d]

Sample Output : [1,3,d,a,c]

JavaScript Question № 53 Practical for Senior

Write a JavaScript program to get the first n Fibonacci numbers.

Note : The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . Each subsequent number is the sum of the previous two.

Sample Input: 7

Sample Output: [ 0 , 1 , 1 , 2 , 3 , 5 , 8 ]

JavaScript Question № 54 Theoretical for Middle

How does prototype work?

JavaScript Question № 55 Theoretical for Junior

What is the scope?

JavaScript Question № 56 Theoretical for Middle

Explain static properties and methods.

JavaScript Question № 57 Practical for Middle

How to find the sum of the elements of an array if the nesting of the array is unknown?

Sample

arraySum([[1, 2, [3, 4]], [9], [10, 12]])

JavaScript Question № 58 Theoretical for Middle

How to redirect the browser to another page?

JavaScript Question № 59 Theoretical for Senior

What are bubbling, capturing, and event delegation in the browser?

JavaScript Question № 60 Practical for Middle

Write a JavaScript function to create random hex color

Sample Output: #31c05f”

JavaScript Question № 61 Theoretical for Middle

What is the difference between import and require?

JavaScript Question № 62 Practical for Senior

Write a code to drag and drop an absolute positioned element.

JavaScript Question № 63 Theoretical for Middle

What are the benefits of debugging the script in the browser?

JavaScript Question № 64 Practical for Senior

How to set an environment variable in the npm script?

JavaScript Question № 65 Theoretical for Senior

Explain the settings of the following eslintrc.json sample

eslintrc.json

{
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "ecmaFeatures": {
            "jsx": true
        }
    },
    "rules": {
        "semi": "error"
    }
}

JavaScript Question № 66 Theoretical for Senior

For what purposes can the global object console be used, besides logging?

JavaScript Question № 67 Theoretical for Middle

What useful plugins / extensions / features can be added in IDE?

JavaScript Question № 68 Theoretical for Middle

What is a destructuring assignment? Give an example.

JavaScript Question № 69 Theoretical for Senior

What is yield, give an example?

JavaScript Question № 70 Practical for Senior

Rewrite the example using promise

const printSec = (number, callback) => {
  setTimeout(() => {
      console.log(`${number} sec`)
      callback()
    },
    1000)
}
printSec(1, () => {
  printSec(2, () => {
    printSec(3, () => {})
  })
})

JavaScript Question № 71 Theoretical for Senior

List examples in which ECMAScript languages ​​are used other than the browser and the web backend.

JavaScript Question № 72 Theoretical for Middle

What is the difference between REST API and GraphQL?

JavaScript Question № 73 Theoretical for Middle

What is PWA?

JavaScript Question № 74 Theoretical for Middle

What is SSR?

JavaScript Question № 75 Theoretical for Middle

What is Static Site Generators?

JavaScript Question № 76 Theoretical for Senior

List types of storage in the browser.

JavaScript Question № 77 Theoretical for Middle

What is a common practice for type checking in JavaScript?

JavaScript Question № 78 Theoretical for Middle

What is Lodash?

JavaScript Question № 79 Theoretical for Middle

What is a Hybrid Mobile App?

JavaScript Question № 80 Theoretical for Middle

What are the disadvantages of using jQuery with SPA?

JavaScript Question № 81 Theoretical for Middle

List some popular libraries for data visualization.

JavaScript Question № 82 Theoretical for Senior

What are the libraries for state management?

JavaScript Question № 83 Theoretical for Junior

List SPA frameworks and libraries.

JavaScript Question № 84 Theoretical for Middle

List the libraries to making requests from the browser and Node.js?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK