The isFinite() is a function that simply checks if the value passed in it is finite number or not. It’s basically used to filter out NaN, undefined or Inifinite numbers. It used to make your code more error-free and robust.  

Let’s see some examples to get a better idea. 

 

Rather, DO THIS:  

 

Or if you want to make it cleaner and 1 liner, you could use Ternary operator like so:  

Want to learn what Ternary Operators are, check out here! 

You could also take it a step further and make it more robust by checking if it’s of Number datatype like so:  

This way, it will also robustly check for the datatype to be only Number. Before it would have still accepted any number in string quotations i.e.  “5”. Now it will make the condition as false if it’s in quotation and would only be true if it’s only a Number datatype.  

That’s it!