- Notifications
You must be signed in to change notification settings - Fork9
A bunch of Javascript idiosyncrasies to beginners.
License
odykyi/javascript-idiosyncrasies
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Do you knowjs ?
before answers to the question please read more than 20 books aboutjs technology and only then answer
please copy this project and share with friends :)
¯\_(ツ)_/¯https://odykyi.github.io/javascript-idiosyncrasies/
https://github.com/odykyi/javascript-idiosyncrasies
This is a collection of things in JavaScript that may not be well recognized, especially to beginners.
Disclaimer: Some of these snippets are simply to demonstrate thequirky parts of JavaScript and by no means encourage best practices and should never be seen in production code.
Q. What's the result?
(function(){return`text 'inner'`==`text "inner"`;})();
A.
falseQ. What's the result?
(function(){varobj={valueOf:function(){return3;},toString:function(){return2;},}returnobj+4;})();
A.
7Q. What's the result?
(function(){varfoo=newObject();varbar=newObject();varmap=newObject();map[foo]='foo';map[bar]='bar';returnmap[foo];})();
A.
"bar"Q. What's the result?
(function(){returnNaN===NaN;})();
A.
falseQ. What's the result?
(function(){functionfoo(){return'a';}returnfoo();functionfoo(){return'b';}})();
A.
"b"Q. What's the result?
(function(limit){for(vari=0;i<limit;i++){setTimeout(function(){console.log(i);},0);}})(3);
A.
333
Q. What's the result?
(function(a,b){arguments[1]=3;returnb;})(1,2);
A.
3Q. What's the result?
(function(a,b,c){deletearguments[0];returnarguments.length;})(1,2,3);
A.
3Q. What's the result?
(function(){return(function(a,b){}).length;})();
A.
2Q. What's the result?
(function(a,b){varfoo,bar;foo=(bar=a,b);returnfoo;})(1,2);
A.
2Q. What's the result?
(function(undefined){varfoo;returnfoo===undefined;})(true);
A.
falseQ. What's the result?
(function(n){return~(n);})(-3);
A.
2Q. What's the result?
(function(n){return~~n;})(-1.5);
A.
-1
Q. What's the result?
(function(x){return!!x;})('a');
A.
trueQ. What's the result?
(function(){returntypeofnull==='null';})();
A.
falseQ. What's the result?
(function(){return+(newDate())})();
A.
1393812837139Q. What's the result?
(function(){return(newDate()).valueOf();})();
A.
1393812845834Q. What's the result?
(function(){return''+(newDate());})();
A.
"Sun Mar 02 2014 18:14:01 GMT-0800 (PST)"Q. What's the result?
(function(){varfoo='a';(function(foo){foo='b';})(foo);returnfoo;})();
A.
"a"Q. What's the result?
(function(){returnarguments.toString();})();
A.
"[object Arguments]"Q. What's the result?
(function(){return(function(){})===(function(){});})();
A.
falseQ. What's the result?
(function(n){returnn===newNumber(n);})(10);
A.
falseQ. What's the result?
(function(x){returnnewString(x)===x;})('a');
A.
falseQ. What's the result?
(function(){return[1+1]===[2];})()
A.
falseQ. What's the result?
(function(){return{foo:'bar'}==={foo:'bar'};})();
A.
falseQ. What's the result?
(function(){for(;;);return1;})();
A.
*Infiniteloop*
Q. What's the result?
(function(){return['10','10','10','10'].map(parseInt);})();
A.
[10,NaN,2,3]
Q. What's the result?
(function(){varo={toString:function(){return'a';},valueOf:function(){return1;}};returno+o;})();
A.
2Q. What's the result?
(function(){varf=functiong(){return1;};returng();})();
A.
ReferenceError:gisnotdefined
Q. What's the result?
(function(){returnvoid(1+1);})();
A.
undefinedQ. What's the result?
(function(){vara=[1,2];varb=a;a=[1,2];returna===b;})();
A.
falseQ. What's the result?
(function(){varx=1;return(function(){returnx;varx=2;})();})();
A.
undefinedQ. What's the result?
(function(n){vareven=function(num){return(num===0)||!(even(num-1))};var_even=even;even=void0;return_even(n);})(2);
A.
TypeError:undefinedisnotafunction
Q. What's the result?
(function(){varn;functionname(){returnthis.name};n=name.bind({name:'foo'});n=n.bind({name:'bar'})returnn();})();
A.
"foo"Q. What's the result?
(function(){return('3'>'12')===('03'>'12');})();
A.
falseQ. What's the result?
(function(){returnMath.pow(2,53)===(Math.pow(2,53)+1);}();
A.
trueQ. What's the result?
(function(){returnMath.pow(2,1024)===Infinity;})();
A.
trueQ. What's the result?
(function(){return(Infinity-100)===Infinity;}();
A.
trueQ. What's the result?
(function(){return(0.1+0.2===0.3);})();
A.
falseQ. What's the result?
(function(){return(0.1).toFixed(20);})();
A.
"0.10000000000000000555"Q. What's the result?
(function(){returnparseFloat('3.3.4');})();
A.
3.3Q. What's the result?
(function(){return010;})();
A.
8Q. What's the result?
(function(){return(parseInt('10000000000000000',10)===parseInt('10000000000000001',10));})();
A.
trueQ. What's the result?
(function(n){return(Function)('var n = n || 2; return n;')(n);})(1);
A.
2Q. What's the result? (assuming window scope)
vara=1;b=1;(function(){return(deletewindow.a)===(deletewindow.b);})();
A.
falseQ. What's the result?
(function(x){varisMatch,regex=/[\w]/gi;return(regex.test(x)===regex.test(x));})('a');
A.
falseQ. What's the result?
(function(){return![];})();
A.
falseQ. What's the result?
(function(){return+[];})();
A.
0Q. What's the result?
(function(){return[][[]];})();
A.
undefinedQ. What's the result?
(function(){return+!+[];})();
A.
1Q. What's the result?
(function(){return[]+[];})();
A.
""Q. What's the result?
(function(){returntrue+1;})();
A.
2Q. What's the result?
(function(){return1/'';})();
A.
InfinityQ. What's the result?
(function(){return1*null;})();
A.
0Q. What's the result?
(function(){returnnewArray()==false;})();
A.
trueQ. What's the result?
(function(){if([]){return[]==false;}})();
A.
trueQ. What's the result?
(function(){return''.concat(null);})();
A.
"null"Q. What's the result?
(function(a,b){returna++b;})('a','b');
A.
"aNaN"Q. What's the result?
(function(){Object.prototype.foo='foo';returnfoo;})();
A.
"foo"Q. What's the result?
(function(){return1000===1e3;})();
A.
trueQ. What's the result?
(function(){return9999999999999999;})();
A.
10000000000000000Q. What's the result?
(function(){(function(){vara=b=1;})();returntypeofa===typeofb;})();
A.
falseQ. What's the result?
(function(){returnArray(3).map(function(o){return'a';});})();
A.
[undefined,undefined,undefined]
Q. What's the result?
(function(){varfoo=[0,1,2];foo[10]=10;returnfoo.filter(function(n){returnn===undefined;});})();
A.
[]
Q. What's the result?
(function(x){varret=null;switch(x){case'A':ret='A';break;default:ret='unknown';break;}returnret;})(newString('A'));
A.
"unknown"Q. What's the result?
(function(){varx={};returnx.prototype===Object.getPrototypeOf(x);})();
A.
falseQ. What's the result?
(function(){functionfoo(){}foo.name='bar';returnfoo.name;})();
A.
"foo"Q. What's the result?
(function(){returnArray(5).join(',').length;})();
A.
4Q. What's the result?
(function(x){returnx+++++x;})(2);
A.
6Q. What's the result?
(function(){'use strict';lettype=typeoffoo;letfoo=1;returntype;})();
A.
ReferenceError:fooisnotdefined
Released under the MIT License.
About
A bunch of Javascript idiosyncrasies to beginners.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
