Skip to content

Instantly share code, notes, and snippets.

@mike1011
Created August 26, 2022 12:32
Show Gist options
  • Save mike1011/b7e4bcca6bc42d72d235081270da3f5d to your computer and use it in GitHub Desktop.
Save mike1011/b7e4bcca6bc42d72d235081270da3f5d to your computer and use it in GitHub Desktop.
javascript questions with console.log
var a={},
b={key:'b'},
c={key:'c'};
a[b]=123;
a[c]=456;
console.log(a[b]);
console.log(a);
Output:
456
{ '[object Object]': 456 }
============================
(function() {
console.log(1);
setTimeout(function(){console.log(2)}, 1000);
setTimeout(function(){console.log(3)}, 0);
console.log(4);
})();
Output:
1
4
3
2
============================
(function() {
console.log(1);
setTimeout(function(){console.log(2)}, 1000);
setTimeout(function(){console.log(3)}, 0);
setImmediate(function(){console.log(5)});
console.log(4);
})();
Output:
1
4
3
5
2
==========================================
console.log(0.1 + 0.2);
console.log(0.1 + 0.2 == 0.3);
Output:
0.30000000000000004
false
========================================
getName();
console.log(x);
var x = 7;
function getName() {
console.log('hi');
}
Output:
hi
undefined
=========================================
console.log([] == [])
Output:
false
==========================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment