These are few Javascript Ouput based interview question, which I faced during my interview process.
Table of Contents
Question 1.
console.log('val1--val:',val1); val1 = 10; test(); var val2 = 20; const test = () => { console.log('hi')} console.log('val2--val:',val2); var val1;
Question 2.
let prom = new Promise((res, rej) => { console.log('synchronously executed'); if (Math.random() > 0.5) { res('Success'); } else { rej('Error'); } }) prom.then((val) => { console.log('asynchronously executed: ' + val); }).catch((err) => { console.log('asynchronously executed: ' + err); console.log('promise done executing'); }); console.log('last log');
Question 3.
let person = { name: 'Anil Singh', age: 32 } let members = [person]; person = null; console.log(members); console.log(person);
Question 4.
let value = { members: 10 }; let multiply = ((x = { ...value }) => { console.log(x.members *= 2) }); multiply(); multiply(); multiply(value); multiply(value);
Question 5.
let a11 = {name:'a'}; let b11 = a11; a11 = {age:30}; console.log(b11, a11);
Question 6.
let obj1 = {}; let obj2 = { a: 2 } let obj3 = { b: 2 } obj1[obj2] = 231; obj1[obj3] = 333; console.log(obj1[obj2])
Question 7.
console.log(11 + 11) console.log(011 + 011) console.log(1 || 2 && 3) console.log(1 && 2 || 3) console.log(0.1 + 0.2 == 0.3)
Question 8.
console.log('1') setTimeout(() => { console.log('Settimeout') }, 0); setInterval(() => { console.log('SetInterval') }, 0); console.log('2')
Question 9.
var valid = true; setTimeout(() => { console.log('Settimeout'); valid = false; }, 100); while(valid) { console.log('hi') }
Question 10.
function output() { console.log(v); let v = 10; } output();
Question 11.
let user = { fname:'singhak', getFname() { const fname = 'singhak.in'; console.log(this.fname); } } user.getFname();