You could just do if (navigator.getDeviceStorage('pictures').length <= 1) here then you don't need to introduce a new variable.