Does anyone know what this code does? It is written in Javascript.
var RocknCoder = RocknCoder || {};
Does anyone know what this code does? It is written in Javascript.
var RocknCoder = RocknCoder || {};
Short for:
if (!RocknCoder) var RocknCoder = {};
{}
is an object initializer. Try verbalizing it and it makes more sense:
set variable RocknCoder equal to RocknCoder or {}
I believe that using the short form is better than the if
simply because it blocks a ReferenceError
from occurring on the if
condition if the variable is not already declared in scope. var
on the declaration may obviate that with hoisting, though.