The isNaN() Function For JavaScript

The isNaN() Function For JavaScript

A Quick, Helpful Built-In When Working With Mathematic Operations. In JavaScript, there is a property of the global object called NaN. NaN is rarely used in writing programs or scripts. It is most often received as a return value when a mathematic (Math) function fails, or when a function fails to parse a number, e.g. parseInt(). NaN is quirky and uncommon, but is occasionally presented and needs to be handled.

A Quick, Helpful Built-In When Working With Mathematic Operations.

In JavaScript, there is a property of the global object called [NaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN). NaN is an abbreviation, rather an acronym, of “Not a Number”, and is not to be confused with the delicious flatbread: naan. NaN is rarely used in writing programs or scripts. In modern web browsers it is a non-configureable and non-writeable property. It is most often received as a return value when a mathematic (Math) function fails, or when a function fails to parse a number, e.g. parseInt(). NaN is quirky and uncommon, but is occasionally presented and needs to be handled.

In a recent project, with a React client side, the user account included a portfolio of collected stocks and corresponding prices. The portfolio had to include a gross sum of total earnings. Sounds easy enough: gather all the stock prices from the portfolio and add them together. Of course, things are never quite as easy as first assumed to be.

Upon a returning user logging into their account, the state was loaded with that user’s stocks, but the prices of these stocks—and, consequently, the total earnings—were dynamically rendered by fetching to an external API for current market prices. The difficulty was properly timing and dispatching actions to fetch data from the server side database and external API while properly rendering components on the client side. Within that chain of events, an action is dispatched which calculates the gross sum of the user’s total earnings, resolved by a function called setTotalEarnings.

Best solutions were to first properly sequence the fetches, promises, and component renders, or craft the setTotalEarnings function to better control the return value, or more simply handle a falsy return value while conditionally rendering, but, as I was building this application in a short time frame for an assessment, I pushed ahead and addressed what was needed to just get the thing working in time! Long story short, the setTotalEarnings function was intermittently returning NaN, and I was having trouble handling it to be rendered correctly in the appropriate React component.

javascript web-development programming developer

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Hire Dedicated eCommerce Web Developers | Top eCommerce Web Designers

Build your eCommerce project by hiring our expert eCommerce Website developers. Our Dedicated Web Designers develop powerful & robust website in a short span of time.

Best Web and App Development Company in Ahmedabad

Contact DataPierce for any questions or queries you have about website development, designing, marketing projects or any small or enterprise software development.

Mobile App Development Company India | Ecommerce Web Development Company India

Best Mobile App Development Company India, WebClues Global is one of the leading web and mobile app development company. Our team offers complete IT solutions including Cross-Platform App Development, CMS & E-Commerce, and UI/UX Design.

For World Class Web Development Services in India visit RB Genie

Do you want excellent and world class web development services for your valuable projects? Contact **RB Genie **now, we have more than 8 years experienced team of web developers, which specializes in overall web design and website development...

Automatic semicolon insertion (ASI) in JavaScript

Semicolons and Automatic Semicolon Insertion are two of the most misunderstood topics in JavaScript. In this tutorial, you will learn about what ASI is. You will also learn about the rules that determine where semicolons are required.