<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>function on Curtis Timson</title><link>https://hugo.curtiscode.dev/tags/function/</link><description>Recent content in function on Curtis Timson</description><generator>Hugo -- gohugo.io</generator><language>en-GB</language><lastBuildDate>Wed, 05 Oct 2016 00:00:00 +0000</lastBuildDate><atom:link href="https://hugo.curtiscode.dev/tags/function/index.xml" rel="self" type="application/rss+xml"/><item><title>Default parameters with ES6</title><link>https://hugo.curtiscode.dev/post/js/default-parameters-es6/</link><pubDate>Wed, 05 Oct 2016 00:00:00 +0000</pubDate><guid>https://hugo.curtiscode.dev/post/js/default-parameters-es6/</guid><description>With ES5 if you wish to set default parameters on a javascript function you would be required to check the value and supply a default if one hadn&amp;rsquo;t been set.
var myFunction = function(arg1, arg2){ arg1 = arg1 || 25; arg2 = arg2 || true; //do something } Even this has problems as passing in 0 for arg1 or false for arg2 would both evaluate as &amp;ldquo;falsey&amp;rdquo; and therefore set the default values.</description></item><item><title>Round to the nearest decimal</title><link>https://hugo.curtiscode.dev/post/js/round-to-the-nearest-decimal/</link><pubDate>Fri, 10 Oct 2014 00:00:00 +0000</pubDate><guid>https://hugo.curtiscode.dev/post/js/round-to-the-nearest-decimal/</guid><description>If we need round to the nearest whole number, we can use the Math.round() function to return this:
Math.round(1.34234); //returns 1 However what if we need to round to a decimal place? For example 0.5.
The following function can be used to do just that, and the logic itself can be adapted to be used for other languages too (C#, SQL etc).
function roundToMultiple(value, multiple){ var t = (1/multiple); return (Math.</description></item><item><title>Check javascript function exists before calling it</title><link>https://hugo.curtiscode.dev/post/js/check-javascript-function-exists-before-calling-it/</link><pubDate>Fri, 23 Nov 2012 00:00:00 +0000</pubDate><guid>https://hugo.curtiscode.dev/post/js/check-javascript-function-exists-before-calling-it/</guid><description>On large applications, there may be some instances where you need to make a call to a function which belongs in a different javascript file.
There might also be a case where this javascript file isn’t always included on every page, and should only be called if it is included.
If we are to call this function, and it hasn&amp;rsquo;t been included, a javascript error will be returned.
Therefore we need to first check that the functions exists in the current context.</description></item></channel></rss>