JS interview questions

  1. What is Object Destructuring? (with examples)
  2. What are the pop-up boxes available in JavaScript?
  3. How do you empty an array in JavaScript?
  4. How do you remove duplicates from a JavaScript array?

1.Object destructuring is a useful JavaScript feature to extract properties from objects and bind them to variables.
2.Alert box, Confirm box, and Prompt box
3.arr.length=0, let arr=[]
4.Using loop an comparing each value using the index.

1 Like

1.syntax for extracting values from an object property and assigning them to a variable.
2. Alert box.
Confirm box.
Prompt box.
3.arr. length = 0;
4. by using filter() method.

1 Like
  1. this allows us to extract data from arrays, objects, and maps and set them into new
    var obj = {first: ‘jack’, last: ‘roy’, age: 20};var first = obj.
  2. Alert box, Confirm box, and Prompt box
  3. array to 0 or arr[ ] or arr.length(0)
  4. set() method
1 Like

1.Object destructing allow to access data from object like array,objects and assign it to new variable.
2.alert box,confirm box,prompt box.
3.assign empty array, set array.length=0, using splice ,using pop.
4.filter,for each, reduce.

1 Like

1ANS:- Object Destructuring is syntax for extracting value from an object property.
2ANS:- Alert box, Confirm box, and Prompt box.
3ANS:- arr.length=0; or arr=[];
4ANS:- set() method.

1 Like
  1. Object destructuring is a feature in JavaScript that allows you to extract data from objects and bind them to variables in a more concise way. It makes it easier to work with objects by reducing the amount of code required to access their properties.

Here’s an example:
const person = {
firstName: ‘John’,
lastName: ‘Doe’,
age: 30
};

const { firstName, lastName } = person;

console.log(firstName); // Output: ‘John’
console.log(lastName); // Output: ‘Doe’

  1. Alert box, Confirm box, Prompt box

  2. In JavaScript, you can empty an array by setting its length property to 0, or by using the splice() method to remove all elements from the array.

  3. Using the Set object: The Set object is a built-in object in JavaScript that lets you store unique values of any type, including arrays. You can convert an array to a set, and then convert the set back to an array to remove duplicates.

1 Like

1.syntax for extracting values from an object
property and assigning them to a variable.
2. Alert box, Confirm box, Prompt box.
3.array. length = 0;
4. using filter() method.

1 Like

1.It allows us to extract properties, from an array​ at a time .
2. Alert(),Confirm (),Prompt()
3.arr. length = 0,arr =[];
4. By using filter(),forEach(),set()

1 Like

1- let person = {firstName:“John”, lastName:“Doe”, age:50, eyeColor:“blue”};
let {firstName, lastName, age, eyeColor} = person

2- alert, prompt, confirm

3- arr=[]

4- we can create new array and check if it includes new item, if it does not includes, we’ll push

1 Like
  1. Object destructuring is an expression which allows us to access the data from objects like arrays, objects, maps and assign it to new variables. Through this object destructuring, we can create variables easily from the object’s properties

  2. An pop-up box is like alert box is often used if you want to make sure information comes through to the user.

let a = [1,2,3];
a = [];
4.
let chars = [‘A’, ‘B’, ‘A’, ‘C’, ‘B’];
let uniqueChars = […new Set(chars)];
console.log(uniqueChars);