JavaScript Arithmetic Demo: parseInt(), typeof, and to Fixed()

Опубликовано: 12 Июль 2022
на канале: Thomas Blum
23
0

In this video we design a page that allows the user to enter two numbers. The page then allows the user to perform four arithmetic operations on the pair of entries. The subtraction, multiplication, and division go through rather easily, but the addition is problematic. The data that comes is is of the "string" type (confirmed by the typeof code). The plus operator is overloaded -- it handles both concatenation and addition. Since the data is of the string type, concatenation is performed. We converted the data to the "number" type using the parseInt() method. After that the plus operator led to the desired addition. We also cleared out the results if the input data was changed by the user. And finally we guarded the division function from dividing by zero.


Смотрите видео JavaScript Arithmetic Demo: parseInt(), typeof, and to Fixed() онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Thomas Blum 12 Июль 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2 раз и оно понравилось людям.