JS is weird
Muhammad Arqam ????
● PSE@Tkxel LLC | Full-Stack Developer | Pre-Sales Engineer | #JavaScript, #TypeScript, #Angular, #React, #NodeJS, #AWS, #CloudArchitecture
When I observe the behavior of JavaScript, I really found it a weird language. It is a compile time as well as scripting language. We use to hear that everything in JS is an object and many other things that make JS a weird language.
Let’s have a look on few examples that shows it’s behavior.
Example 1: typeOf(NaN) is a number.
Example 2: typeOf([]) is an object
Example 3: 9999999999999999 = 10000000000000000
Example 4: 0.1 + 0.3 = 0.4 But 0.1 + 0.2 != 0.3
Example 5: [] + [] = “”
Example?6: [] + {} = “[object, Object]”
Example 7: {} + [] = 0
Example 8: true + true + true = 3
Example 9: true - true = 0
Example 10: true == 1 (it is correct) BUT true === 1 (It is incorrect, false)
Example 11: [] == 0
Example 12: true + false = 1
Example 13: 10,2 = 2
Example 14: !!!true = false
Example 15: 010 - 03 = 5