Weird JavaScript - Part 1 🧑‍💻
imsabir

imsabir @msabir

About: I am web developer with expertise in cutting edge technologies, technical writer, technical recruiter. I believe in #Gratitude. ✨✨✨

Location:
Somewhere on Earth, Universe 🌎
Joined:
Feb 22, 2022

Weird JavaScript - Part 1 🧑‍💻

Publish Date: Feb 24 '22
14 12

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

Comments 12 total

  • imsabir
    imsabirFeb 24, 2022

    Follow @msabir for more such weird parts!! Also, You will receive daily update of why JS works like this,** JS under the hood ** article which I will be publishing in some time. Cheers!!

  • drmikecrowe
    drmikecroweFeb 24, 2022

    Nothing
    0 3 3

  • ''
    ''Feb 25, 2022
    1. Nothing
    2. 0 2 2
  • Rahul Bhaskar
    Rahul BhaskarFeb 25, 2022

    Nothing
    1 1 2

  • Taiko
    TaikoFeb 26, 2022

    i don't think there is anything weird with WJS-2 example. These operators are supposed to work like this in most (if not all) programming language.
    num++ -> return then increment
    ++num -> increment then return

  • imsabir
    imsabirFeb 27, 2022

    Updated the answers folks

  • АнонимMar 8, 2022

    [hidden by post author]

  • Mohammad Mahdi Bahrami
    Mohammad Mahdi BahramiJul 17, 2024

    You need to learn grammar...

  • Daniel Edwards
    Daniel EdwardsMar 9, 2025

    Yo what to plo

Add comment