2021 week 36, mathematically incorrect JS.

Plus numbers about the Malaysian flag.

Sep 12, 2021

A doodle of the Malaysian flag with the word number in Chinese, Malay, and English on the left.

It’s 2021 week 36, I recently had a bit of fun with JavaScript number data type and Malaysia Day is around the corner (16th September) - that’s how I arrive at this week’s topics. Here are some interesting facts about numbers in JavaScript and numbers related to the Malaysian flag.

  • JavaScript number: the primitive data type number is based on the IEEE 754 standard, which means floating-point arithmetic applies. The classic example is 0.1 + 0.2 returns 0.30000000000000004, the result also shows the decimal precision limit of 17.

  • JavaScript bigint: the bigint primitive type was introduced in ES2020, it can safely represent integers bigger than Number.MAX_SAFE_INTEGER, e.g. 9007199254740992 === 9007199254740993 returns true which is wrong but with BigInt, 9007199254740992n === 9007199254740993n returns false as expected. Note that as of current, the Math object doesn’t work with bigint.

  • The Malaysian flag: before the formation of Malaysia in year 1963, the flag for Federation of Malaya had 11 stripes and the star had 11 points as opposed to 14 for both now. The original submission of the design had a five-pointed star.

This is my 9th weekly post, thank you for reading and if you have got any feedback, do let me know!