Pergunta de entrevista da empresa Zehn Solutions

1. const shape = { radius: 10, diameter() { return this.radius * 2; }, perimeter: () => 2 * Math.PI * this.radius, }; console.log(shape.diameter());// console.log(shape.perimeter());//
20 NaN 
let obj = { x: 2, getX: function() { setTimeout(() => console.log('a'), 0);// new Promise( res => res(1)).then(v => console.log(v));// setTimeout(() => console.log('b'), 0);// } } obj.getX();

o/p :- promise , first SetTimeOut and then second SetTimeOut :- 1,a,b



var a = 10; function abc(){ console.log(a);// var a = 20; console.log(a);// } console.log(a);// abc();//


10
10, error can not redeclare a as it is global scoped

10 undefined 20 


var a = {'key': 100}; var b = [] b[a] = 90; console.log(b);//

[object Object]: 90 var a = 50; var b = { name : 'abc' }; function abc(a,b){ console.log(a,b);// b.name = 'cde'; console.log(a,b);// } abc();// abc(a,b);// console.log(a,b);//

50, { name : 'abc' } -> 50, { name : ‘c’de }
50, { name : 'abc' } -> 50, { name : ‘c’de }
50, { name : 'abc' }


undefined undefined undefined undefined 50 { name: 'abc' } 50 { name: 'cde' } 50 { name: 'cde' } 

function foo() { let a = b = 0; a++; return a; } foo(); console.log(typeof a); // console.log(typeof b); //

1
undefined number 

 let a =10 { var a = 20 } console.log(a);//
SyntaxError: Identifier 'a' has already been declared