Weird JavaScript - Part 1 š§āš»
imsabir
Posted on February 24, 2022
Hey I am Javascript!!
Instead Weird Javascript.
Its look simple but its not !!
As being said, lets move straight to see some Weird parts:
Note: You can comment your answers
WJS - 1
function bark() {
console.log('š barkk barkk!š ');
}
bark.animal = 'dog';
š„š„ What you think it will output šØāš» ?
Answer:
with bark.animal=dog
, one more element is get added to function bark()
, don't be surprise, Everthing is Object in JavaScript and thats why its wired
One more
WJS - 2
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
š„š„ What you think it will output šØāš» ?
Answer:
let number = 0;
console.log(number++); // Output : 0 and then increment it by 1 its known as return then increment
console.log(++number); // Output: 2 AND its increment then return
console.log(number); // it will log latest value of number i.e. 2
0 2 2
Follow @msabir for more
š šŖ š
š©
imsabir
Posted on February 24, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.