xxxxxxxxxx
//Javascript Interview Questions
var a = [15];
var b = [15];
console.log(a[0] == b[0]);
//ture
console.log(a[0] === b[0]);
//true
xxxxxxxxxx
//Javascript Interview Questions
var a = [];
var b = [];
console.log(a == b);
//false
console.log(a === b);
//false
xxxxxxxxxx
What is the output of 10+20+"30" in JavaScript?
3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).
xxxxxxxxxx
//Javascript Interview Questions
var a = [];
var b = a;
console.log(a == b);
// true
console.log(a === b);
// true
xxxxxxxxxx
// Here are some commonly asked JavaScript interview questions:
// 1. What is JavaScript?
// 2. What are the data types in JavaScript?
// 3. Explain the difference between `null` and `undefined` in JavaScript.
// 4. Describe how prototypal inheritance works in JavaScript.
// 5. How does hoisting work in JavaScript?
// 6. Explain the concept of closures in JavaScript.
// 7. What is event delegation in JavaScript?
// 8. How do you handle asynchronous operations in JavaScript?
// 9. What is the purpose of the `this` keyword in JavaScript?
// 10. How can you check the type of a variable in JavaScript?
// Feel free to ask more specific questions or dive deeper into each topic mentioned above.
xxxxxxxxxx
var scope = "global scope";
function check()
{
var scope = "local scope";
function f()
{
return scope;
}
return f;
}
xxxxxxxxxx
function addFourNumbers(num1,num2,num3,num4){
return num1 + num2 + num3 + num4;
}
let fourNumbers = [5, 6, 7, 8];
addFourNumbers(fourNumbers);
// Spreads [5,6,7,8] as 5,6,7,8
let array1 = [3, 4, 5, 6];
let clonedArray1 = [array1];
// Spreads the array into 3,4,5,6
console.log(clonedArray1); // Outputs [3,4,5,6]
let obj1 = {x:'Hello', y:'Bye'};
let clonedObj1 = {obj1}; // Spreads and clones obj1
console.log(obj1);
let obj2 = {z:'Yes', a:'No'};
let mergedObj = {obj1, obj2}; // Spreads both the objects and merges it
console.log(mergedObj);
// Outputs {x:'Hello', y:'Bye',z:'Yes',a:'No'};
xxxxxxxxxx
(function(){
var a = b = 3;
})();
console.log("a defined? " + (typeof a !== 'undefined'));
console.log("b defined? " + (typeof b !== 'undefined'));
xxxxxxxxxx
"use strict";
x = 23; // Gives an error since 'x' is not declared
var x;
xxxxxxxxxx
function sumOfThreeElements(elements){
return new Promise((resolve,reject)=>{
if(elements.length > 3 ){
reject("Only three elements or less are allowed");
}
else{
let sum = 0;
let i = 0;
while(i < elements.length){
sum += elements[i];
i++;
}
resolve("Sum has been calculated: "+sum);
}
})
}