Last active
January 14, 2019 08:00
-
-
Save msaxena25/7fb8323a20107b2f1bd90dcafceed571 to your computer and use it in GitHub Desktop.
JavaScript Awesome console Outputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Both are same! | |
var obj = new Object(); //Empty Object | |
var obj = new Object; //same result | |
2. var obj = new Object(id: 1, name: "test"); | |
Output > it will give error | |
3. | |
var obj1 = {id: 1, name: "test"}; | |
var obj2 = new Object(obj1); //obj1 and obj2 points to the same one | |
obj2.id = 2; | |
console.log(obj1.id); // 2 | |
4. | |
var arr1 = new Array(10); | |
arr1[0] = undefined but arr1.length = 10 | |
5. var arr = Array.from("123"); | |
output > arr will be [1,2,3] | |
0/0 > NaN | |
1/0 > Infinity | |
-1/0 > -Infinity | |
-0/0 > NaN | |
"" /0 > NaN | |
typeof NaN > number | |
typeof Infinity > number | |
typeof -Infinity > number | |
typeof undefined > 'undefined' | |
typeof undefined == undefined > false | |
typeof undefined == 'undefined' > true | |
typeof null > 'object' | |
typeof -null > number | |
typeof "" > string | |
typeof -"" > number | |
typeof -"mohit" > number : -"mohit" gives result NaN | |
console.log("-Mohit") > -Mohit | |
console.log(-"Mohit") > NaN | |
But -"Mohit" == NaN false | |
NaN == NaN > false because NaN never equal to anyone | |
undefined == undefined > true | |
isNaN(0/0) > true | |
isNaN(NaN) > true | |
isNaN("mohit") > true | |
isNaN("") > false | |
isNaN("12") > false | |
isNaN(-"12") > false | |
isNaN(-"mohit") > true | |
"" == [] > true | |
0 == [] > true | |
0 === [] > false | |
[] == [] > false because it is same as new Array() == new Array() | |
{} == {} > false because it is same as new Object() == new Object() | |
[] == false > true | |
[] == true > false | |
(null < 0) >> false | |
null > 0 >> false | |
null < Infinity >> true | |
null < -Infinity >> false | |
console.log(!0) > true because it is same as !false | |
console.log(!'0') > false because it is same as !true | |
var obj = {a :1, b: 2, c: 3}; | |
what will output for below? | |
for (let item in a) {console.log(item)} // a b c | |
for (let item of obj) {console.log(item)} // Uncaught TypeError: obj is not iterable | |
x = 5; | |
console.log(x); | |
var x; | |
output > 5 | |
var x = 10; | |
console.log(x); | |
var x; | |
console.log(x); | |
output > | |
10 | |
10 | |
var x; | |
console.log(x); | |
var x = 12; | |
console.log(x); | |
output > | |
undefined | |
12 | |
var x = 1; | |
console.log(x, y); | |
var y = 6; | |
output > 1 undefined | |
[] + [] | |
output > "" | |
{} + {} | |
output > "[object object][object object]" | |
[] + "hello".split('') | |
output > "h,e,l,l,o" // because it first convert to string before concatenate. | |
console.log('undefined' + undefined); | |
undefined = null; | |
console.log(undefined); | |
output > | |
undefinedundefined | |
undefined | |
console.log(x); | |
x = 45; // it will not be hoisted because it is not declearted by var. | |
output > ReferenceError: x is not defined | |
JAVASCRIPT SET VS ARRAY | |
https://medium.com/front-end-weekly/es6-set-vs-array-what-and-when-efc055655e1a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment