Weird JavaScript - Part 1 šŸ§‘ā€šŸ’»

msabir

imsabir

Posted on February 24, 2022

Weird JavaScript - Part 1 šŸ§‘ā€šŸ’»

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';
Enter fullscreen mode Exit fullscreen mode

šŸ”„šŸ”„ 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);
Enter fullscreen mode Exit fullscreen mode

šŸ”„šŸ”„ 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
Enter fullscreen mode Exit fullscreen mode

Follow @msabir for more

šŸ’– šŸ’Ŗ šŸ™… šŸš©
msabir
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.

Related