Weird parts of JavaScript

In this blog I am going to share my experience when I was looking for a job switch and came across the Weird part of JavaScript.

why? why? why? why JS?
why? why? why? why again JS?

So, lets discuss why this happened.
For the first image the reason is not JS only this issue is because of Floating-point arithmetic. The fix is easy console.log((0.1 + 0.2).toFixed(1)); to get an idea about toFixed() click toFixed().

For the second image the reason is only and only JavaScript behavior. In JS when plus operator is placed between number , boolean or string JS start processing the data from left to right and keep on converting (coerced) the data type. in out case 1+3 = 4, then 4 + true = 4+1 = 5 and finally 5 + ‘medium’ = ‘5’ + ‘medium’ = ‘5medium’ you can verify this by console.log(typeof(1+3+true+'medium')); it will return string.
Note: Once string is converted everything on right will be a string.

Thanks for reading.. suggestions are welcomed in the comments. 😄

JavaScript, Angular Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store