DEV Community

Avinashd
Avinashd

Posted on

Js in bits - 8.9(basic operators)

Learning js should be fun. It is fun if it's easy.
I tried my best in writing this, to understand it the easy way.

Practise Exercises

Let your thoughts flow....

Image description

Leave y'r thoughts....

Top comments (2)

Collapse
 
rybama profile image
Marcin Rybacki

All is quite logical here. Three observations here.

  1. There are operators that only exist in math are (*, /, -). They try to convert literal into number and calculate. If it's not possible, than NaN
  2. Whether '+' is concat or math operator depends on the type of left argument.
  3. There's a curious case of null converted to 0, but undefined converted to NaN, also ' \t \n' converted to 0
Collapse
 
avinashd10 profile image
Avinashd

1, Yes correct
2, + can do 2 things, concat or addition.
addition if both operands are numbers
concat if one of them is a string

This clears out any confusion:
dev.to/avinashd10/js-in-bits-82bas...

3, Math conversion rules gives more clarity
dev.to/avinashd10/js-in-bits-7type...

Happy learning.

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay