Hey Rowdy Coders, In my recent job switch, I have been interviewed at many companies. In this article, I will be sharing all the Top 50 Most Asked JavaScript output-based Interview Questions and Answers.
JavaScript Interview Questions
⭐️. Guess the output of the following code?
console.log(5 > '15' < 5);
console.log(7 < '15' < 7);
console.log(7 < '85' > 5);
⭐️. Guess the output of the following code?
console.log(1);
setTimeout(() => {
console.log(2);
}, 1000);
setTimeout(() => {
console.log(3);
}, 0);
console.log(4);
⭐️. Guess the output of the following code?
console.log(1);
setTimeout(() => {
console.log(2);
}, 1000);
setTimeout(() => {
console.log(3);
}, 0);
Promise.resolve(1).then(function resolve() {
setTimeout(() => {
console.log(4);
}, 0);
});
console.log(5);
⭐️. Guess the output of the following code?
for (var i = 0; i < 4; i++) {
console.log(i);
}
for (let i = 0; i < 4; i++) {
console.log(i);
}
⭐️. Guess the output of the following code?
for (var i = 0; i < 4; i++) {
setTimeout(() => {
console.log(i);
}, 500);
}
for (let i = 0; i < 4; i++) {
setTimeout(() => {
console.log(i);
}, 7000);
}
for (var i = 0; i < 4; i++) {
(function (i) {
setTimeout(function () {
console.log(i);
}, 14000);
})(i);
}
⭐️. Guess the output of the following code?
console.log(["a"] + ["b"]);
console.log([] + []);
console.log(![]);
console.log(![] + []);
⭐️. Guess the output of the following code?
console.log(3 < 4 < 5);
console.log(3 > 4 > 5);
console.log(3 > 4 > -1);
⭐️. Guess the output of the following code?
const x1 = new Promise((res, req) => {
setTimeout(res, 500, "one");
});
const x2 = new Promise((res, req) => {
setTimeout(res, 100, "two");
});
Promise.all([x1, x2]).then((res) => {
console.log(res);
});
Promise.race([x1, x2]).then((res) => {
console.log(res);
});
⭐️. Guess the output of the following code?
const a = {};
const b = { key: "b" };
const c = { key: "c" };
a[b] = 143;
a[c] = 286;
console.log(a[b]);
console.log(b.toString());
⭐️. Guess the output of the following code?
const h1 = { h: "Thor", i: "IM" };
const h2 = { h: "Thor", i: "IM" };
const h3 = h2;
console.log(h1 == h2);
console.log(h1 === h2);
console.log(h2 === h3);
⭐️. Guess the output of the following code?
const array1 = [1, 2, 3];
const array2 = [1, 2, 3];
const array3 = array2;
console.log(array1 === array2);
console.log(array2 === array3);
const User = function (name) {
this.name = name;
};
const user1 = new User("Rowdy");
const user2 = new User("Rowdy");
console.log(user1 == user2);
⭐️. Guess the output of the following code?
console.log((1 && 2) || 0 || 3);
console.log(null && undefined);
console.log(0 || (1 && 2) || 3);
console.log(null || (2 && 3) || 4);
⭐️. Guess the output of the following code?
console.log('goog' > 'bad');
console.log('Like' < 'like');
console.log('Subscribe' > 'Subg');
console.log('SubScribe' > 'Subg');
⭐️. Guess the output of the following code?
console.log("9" > "11");
console.log("9" > 11);
console.log("" > -1);
console.log("Rowdy" > 1);
⭐️. Guess the output of the following code?
console.log(Math.round(5.51));
console.log(Math.round(-5.51));
console.log(Math.floor(5.51));
console.log(Math.floor(-5.51));
console.log(Math.ceil(5.51));
console.log(Math.ceil(-5.51));
console.log(Math.abs(-5.51));
console.log(Math.abs(5.51));
⭐️. Guess the output of the following code?
function Name() {
return
{
mes: "JavaScript";
}
}
console.log(Name());
function caName() {
return {
mes: "Rowdy Coder",
};
}
console.log(caName());
⭐️. Guess the output of the following code?
var array = [1, 2, 3, 4, 5];
console.log(array.length);
array.length = 3;
console.log(array.length);
console.log(array);
delete array[0];
console.log(array);
console.log(array[0]);
console.log(array.length);
⭐️. Guess the output of the following code?
const arr = [1, 2, 3];
const str = "1,2,3";
console.log(arr == str);
⭐️. Guess the output of the following code?
console.log(3 + 3 + "3" + 3 + 3);
console.log(1 + 2 + 3 + 4 + 5 + "6");
⭐️. Guess the output of the following code?
var arr1 = [
[1, 2],
[2, 4],
[4, 8],
];
var arr2 = [...arr1];
arr1[0][1] = "1";
arr1[0][0] = "0";
arr1[1] = 33;
arr1[0] = 22;
console.log(arr1);
console.log(arr2);
⭐️. Guess the output of the following code?
var testArrowFunc = {
name: "abc",
foo: () => {
console.log(this.name);
},
};
var output = testArrowFunc.foo;
output();
testArrowFunc.foo();
var testFunc = {
name: "abc",
foo: function () {
console.log(this.name);
},
};
var output = testFunc.foo;
output();
testFunc.foo();
⭐️. Guess the output of the following code?
console.log(0.1 + 0.2 == 0.3) ;
console.log(0.3 + 0.6 == 0.9) ;
// Output in explanation!
console.log(0.1 + 0.2)
console.log(0.3 + 0.6)
⭐️. Guess the output of the following code?
console.log("first");
setTimeout(() => {
console.log("second");
});
queueMicrotask(() => {
console.log("third");
});
⭐️. Guess the output of the following code?
console.log(num);
var num;
num = 6;
console.log(num);
numb = 6;
console.log(numb);
let numb;
⭐️. Guess the output of the following code?
function* myGenerator() {
yield 1;
yield 2;
yield 3;
}
const gen = myGenerator();
console.log(gen.next());
⭐️. Guess the output of the following code?
console.log(6 + "7");
console.log(true + 5);
console.log(true + "5");
⭐️. Guess the output of the following code?
function exm() {
const name = "Rowdy Coders";
function inner() {
return name;
}
return inner;
}
const inner_func = exm();
console.log(inner_func);
console.log(inner_func());
⭐️. Guess the output of the following code?
console.log("begins");
setTimeout(() => {
console.log("setTimeout 1");
Promise.resolve().then(() => {
console.log("promise 1");
});
}, 0);
new Promise(function (resolve, reject) {
console.log("promise 2");
setTimeout(function () {
console.log("setTimeout 2");
resolve("resolve 1");
}, 0);
}).then((res) => {
console.log("dot then 1");
setTimeout(() => {
console.log(res);
}, 0);
});
⭐️. Guess the output of the following code?
async function async1() {
console.log("async1 start");
await async2();
console.log("async1 end");
}
async function async2() {
console.log("async2");
}
console.log("script start");
setTimeout(function () {
console.log("setTimeout");
}, 0);
async1();
new Promise(function (resolve) {
console.log("promise1");
resolve();
}).then(function () {
console.log("promise2");
});
console.log("script end");
⭐️. Guess the output of the following code?
new Promise(function (resolve, reject) {
setTimeout(function () {
resolve("Promise");
}, 1000);
}).then(function (result) {
console.log(result);
});
setTimeout(callback, 2000);
// setTimeout()
setTimeout(function () {
console.log("setTimeout()");
}, 2000);
// Callbacks
function callback() {
console.log("Callback");
}
process.nextTick(function () {
console.log("process.nextTick()");
});
⭐️. Guess the output of the following code?
const obj = {
name: "Billy",
sing: function () {
this.age = "20";
console.log("a", this);
var anotherFunction = function () {
this.age = "30";
console.log("b", this);
};
anotherFunction();
},
};
obj.sing();
⭐️. Guess the output of the following code?
const a = {
count: 0,
};
const b = a;
b.count = a.count++;
console.log(b.count, a.count);
⭐️. Guess the output of the following code?
const a1 = {
count: 0,
};
const b1 = a1;
b1.count = ++a1.count;
console.log(b1.count, a1.count);
⭐️. Guess the output of the following code?
const s = {
hello: "sri",
34: undefined,
1: "HELLO",
2: "SSS",
};
s["assign"] = "world";
s[-4] = "mee";
console.log(Object.keys(s));
⭐️. Guess the output of the following code?
(function (x) {
console.log("First IIFE executed");
return (function (y) {
console.log("Nested IIFE executed", x);
})(2);
})(1);
⭐️. Guess the output of the following code?
var obj = {
name: "sri",
age: 10,
}
var obj1 = obj;
obj1.age = "20";
Object.freeze(obj);
obj1.age = "30";
console.log(obj.age);
console.log(obj1.age);
⭐️. Guess the output of the following code?
console.log('start');
setTimeout(()=>{
console.log('mid');
}, 0);
for(let i=0;i<10000;i++){
console.log('thread block');
}
console.log('end');
⭐️. Guess the output of the following code?
console.log(varA);
console.log(letB);
var varA = "Rowdy Coders";
let letB = 'Subscribe';
⭐️. Guess the output of the following code?
let value = "Rowdy Coders"
value[1] = "A";
console.log(value);
console.log(value[0], value[1]);
⭐️. Guess the output of the following code?
function tryCatchFinally(){
try {
console.log("try");
return;
} catch(e){
console.log("error");
return;
} finally {
console.log("finally");
return;
}
}
tryCatchFinally();
⭐️. Guess the output of the following code?
let flag = true;
setTimeout(()=>{
flag = false;
}, 1000)
while(flag){
console.log("Does it execute?")
}
⭐️. Guess the output of the following code?
abc();
function abc(){
console.log("1");
}
function abc(){
console.log("2");
}
function abc(){
console.log("3");
}
⭐️. Guess the output of the following code?
const person ={
name: "Rowdy",
age: 1,
name: "Coders"
}
console.log(person);
If you think this content is helpful then please do subscribe to my YouTube channel. This will encourage me to update more latest interview questions, and also lets connect over LinkedIn.
Believe me, By just following the content in Rowdy Coders, you would be able to crack 20+ LPA offer easily. Even for 50LPA you will be seeing these questions only.