Hi Everyone,
Setting default values is one of my favourite things to do when creating JavaScript applications. While working, i came across a bug that could have easily escaped me.
This is how the object is used.
var obj = new App({
imgs: [];
preload: false
});
This is how the object is defined.
var App = function(o) {
this.imageFolder = o.imgs;
this.preload = o.preload || true; // the idea is to set a default value of true
if(this.preload) {
// preload images here
}
}
My question is, how do you handle boolean values when using the || operator