Best way to prevent/handle divide by 0 in javascript

后端 未结 8 2020
天命终不由人
天命终不由人 2020-12-01 09:12

What is the best way to prevent divide by 0 in javascript that is accepting user inputs. If there is no particular way to achieve this what would be the best way to handle s

8条回答
  •  臣服心动
    2020-12-01 09:54

    Hope this is useful

    (denominator != 0 ? numerator/denominator : Infinity)
    

    or whatever value you want to put at the end.

    Greetings.

提交回复
热议问题