Skip to content

Latest commit

History

34 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Essential JavaScript Interview Questions

1. Explain the result of output:

(functiontest(){console.log({}.constructor===arguments.constructor,[].constructor===arguments.constructor);})();

2. Explain the result of output:

(functiontest(arguments){console.log(arguments[0]);})(100);
(functiontest(){vararguments;console.log(arguments[0]);})(200);
(functiontest(){functionsum(){varsum=0,i;for(iinarguments){sum+=i;}returnsum;}console.log(sum(10,20,30,40,50));})();

3. Explain the result of output:

(functiontest(){console.log(function(){}instanceofObject,function(){}instanceofFunction,FunctioninstanceofObject,ObjectinstanceofFunction);})();

4. Explain the result of output:

(functiontest(){console.log(function(){}.apply.length);})();

5. Explain the result of output:

(functiontest(){console.log(Function===Object.constructor,Function===Number.constructor,Function===Function.constructor,Function===Window.constructor,Function===Function.prototype.constructor,Object===Object.prototype.constructor,Number===Number.prototype.constructor,Array===Array.prototype.constructor,Window===Window.prototype.constructor);})();

6. Explain the result of output:

(functiontest(){console.log(typeofObject.prototype,typeofString.prototype,typeofRegExp.prototype,typeofFunction.prototype);})();
(functiontest(){console.log(typeofundefined,typeoftypeofundefined,typeofnull,typeof1/null,typeof[],typeof{},typeofdocument);})();
(functiontest(){console.log(typeofInfinity,typeofNaN,typeof{null: null}.null,typeof{NaN: NaN}.NaN,typeof{Infinity: Infinity}.Infinity);})();

7. Explain the result of output:

(functiontest(){varfn=function(){returnthis*2;};console.log(fn.apply(undefined));console.log(fn.apply(null));console.log(fn.apply(1));})();
(functiontest(){'use strict';varfn=function(){returnthis*2;};console.log(fn.apply(undefined));console.log(fn.apply(null));console.log(fn.apply(1));})();

8. Explain the result of output:

(functiontest(){console.log(Object.prototype.toString.call([]),Object.prototype.toString.call({}),Object.prototype.toString.call(Window),(16).toString(16),(true).toString(16),(false).toString(16));})();

9. Explain the result of output:

(functiontest(){varsum=function(a,b){returna+b;};console.log(typeofsum.call.apply);console.log(sum.call.apply(null,[1,2]));})();

10. Explain the result of output:

(functiontest(){console.log(void(p=1/""),p);})();

11. Explain the result of output:

(functiontest(){(function(){a=1;vara=2;})();console.log(a);})();
(functiontest(){vara=1;functiontest(){if(!a){vara=10;}console.log(a);}test();console.log(a);})();
(functiontest(){(function(){vara=b=3;})();console.log(typeofa,typeofb);})();

12. Which a variant is preferable and why?

(functiontest(){console.log(error!==undefined&&error.x);})();
(functiontest(){console.log(typeoferror!=='undefined'&&error.x);})();

13. Explain the result of output:

(functiontest(){vara=[];console.log(a.length,[,].length,[,,].length);a.length=-1;console.log(a.length);})();
(functiontest(){vara=[1,2,3,4,5];a.length=null;console.log(a[4]);})();
(functiontest(){vara=[1,2,3,4,5];a.length=undefined;console.log(a[4]);})();
(functiontest(){vara=[[[1],2],3];console.log(a.length);})();
(functiontest(){console.log([1,2,[3,4]]+[[5,6],7,8]);})();

14. Explain the result of output:

(functiontest(){console.log(9<5<1,2<6<1,1<3<4);})();

15. Explain the result of output:

(functiontest(){functionfn(){return{value: "test"}}console.log(typeoffn());})();

16. Explain the result of output:

(functiontest(){functionsum(a,b){returna+b;}functionsum(c){returnc;}console.log(sum(3));console.log(sum(2,4));})();

17. Explain the result of output:

(functiontest(){a=1;window.b=2;this.c=3;vard=4;deletea;deleteb;deletec;deleted;console.log(typeofa,typeofb,typeofc,typeofd);})();

18. Explain the result of output:

(functiontest(){vara=1;setTimeout(function(){a=0;console.log('Hi!');},0);while(a){}console.log('Hello!');})();

19. Explain the result of output:

(functiontest(){console.log([]-[],[]+[],{}-{},{}+{});})();

20. Explain the result of output:

(functiontest(){varholder={value: 1},holder2=holder;holder.result=holder={value: 0};console.log(holder.result,holder2);})();

21. Explain the result of output:

(functiontest(){vartest={property: 'Value',getPropertyValue: function(){returnthis.property;}};vargetPropertyValue=test.getPropertyValue;console.log(getPropertyValue(),test.getPropertyValue());})();
(functiontest(){"use strict";varholder,fn;holder={holderFn: function(){console.log(this);}};fn=holder.holderFn;holder.holderFn();fn();})();

22. What is the maximum depth of the stack, starting with the "test" function?

vara=[1,2,3,4,5];(functiontest(){console.log((newError()).stack);varitem=a.pop();item&&setTimeout(arguments.callee,0);})();
vara=[1,2,3,4,5];(functiontest(){console.log((newError()).stack);varitem=a.pop();item&&arguments.callee();})();

23. Explain the result of output:

(functiontest(){functionfn(){arguments.callee.count=arguments.callee.count||0;returnarguments.callee.count++;}console.log(fn(),fn(),fn());})();

24. Explain the result of output:

(functiontest(){vara='5',b=2,c=a+++b;console.log(c);})();

25. Explain the result of output:

console.log(016*2,0x16*2);
console.log(Math.floor(999.99)===~~999.99,Math.floor(-999.99)===~~-999.99,~function(){}(),~~function(){}(),~~null,~~undefined,~~[],~~{},~~'Test');
console.log(1+"2"+"2",1++"2"+"2",1+-"1"+"2",+"1"+"1"+"2","2"*3,"6"/2,"A"-"B"+"2","A"-"B"+2);
console.log(0.1+0.2);console.log(0.1+0.2===0.3);console.log((0.1+0.2)+0.3===0.1+(0.2+0.3));
console.log(Number('Test!'),Number(''),Number('00010'),Number(true),Number(NaN),parseInt('2',2),parseInt('011',8),parseInt('011',10),parseInt('00C',16),parseInt([10,9,8,7,6,5,4,3,2,1]),1/-0,isNaN(1/-0),isFinite(1/-0),0/-0,isNaN(0/-0),isFinite(0/-0),1/0,isNaN(1/0),isFinite(1/0),0/0,isNaN(0/0),isFinite(0/0),NaN===NaN,Infinity===Infinity);

26. Explain the result of output:

console.log(true==[1]&&true==[2]);
console.log(newBoolean()==true,newBoolean("")==true,newBoolean("0")==true,newBoolean("1")==true,newBoolean("true")==true);
console.log(false=='0',false==='0',true=='1',true==='1',true=='2',true==='2');

27. Explain the result of output:

(function(){varfn=function(){console.log(typeofthis);};fn.call("Hello World!");})();(function(){"use strict";varfn=function(){console.log(typeofthis);};fn.call("Hello World!");})();
console.log((function(){return(newthis).stack;}).apply(Error));

28. Explain the result of output:

(functiontest(){vara={},b={value: 'test1'},c={value: 'test2'};a[b]='test3';a[c]='test4';console.log(a[b]);})();

29. Explain the result of output:

console.log(Date(),newDate,+Date(),+newDate,+newDate(),+newDate()===+newDate);

30. Explain the result of output:

console.log(typeofconfirm('Do you like JavaScript?'));

31. Eliminate non-existent state of promise.

  1. fulfilled
  2. awaiting
  3. pending
  4. refused
  5. rejected
  6. interrupted

32. Explain the result of output:

(functiontest(){console.log([1,2,3,4,5].map(function(n){returnn===1&&1||arguments.callee(n-1)*n;}));})();
(functiontest(){"use strict";console.log([1,2,3,4,5].map(function(n){returnn===1&&1||arguments.callee(n-1)*n;}));})();

33. Explain the result of output:

(functiontest(){vars1='test',s2=newString('test'),s3=String('test');console.log(s1==s2,s1===s2,s1==s3,s1===s3,s1.constructor===s2.constructor,s1.constructor===s3.constructor,typeofs1,typeofs2,typeofs3);console.log(s1.slice()==s1,s1.slice()==s2,s1.slice()==s3,s1.slice()===s1,s1.slice()===s2,s1.slice()===s3);s1[2]='w';console.log(s1);})();

About

[JOB][Essential JavaScript Interview Questions]

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors