<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>negative-number on Curtis Timson</title><link>https://hugo.curtiscode.dev/tags/negative-number/</link><description>Recent content in negative-number on Curtis Timson</description><generator>Hugo -- gohugo.io</generator><language>en-GB</language><lastBuildDate>Wed, 30 Apr 2014 00:00:00 +0000</lastBuildDate><atom:link href="https://hugo.curtiscode.dev/tags/negative-number/index.xml" rel="self" type="application/rss+xml"/><item><title>Default negative variables to zero in javascript</title><link>https://hugo.curtiscode.dev/post/js/default-negative-variables-to-zero-in-javascript/</link><pubDate>Wed, 30 Apr 2014 00:00:00 +0000</pubDate><guid>https://hugo.curtiscode.dev/post/js/default-negative-variables-to-zero-in-javascript/</guid><description>If you need to default a value to 0 if its negative, you could do:
var i = -45; if (i&amp;lt;0){ i = 0; } console.log(i); //0 However, a shorter way of doing this would be to use Math.max() passing 0 as one of the parameters:
var i = -45; i = Math.max(0,i); console.log(i); //0 Likewise Math.min() can be used to set a maximum value:
var i = 999; i = Math.</description></item></channel></rss>