Simple question, What is the best practise, should I declare JavaScript objects, that will not be initialized until some later stage, with null
or {}
?
I think it really depends. If you just want to declare it early because you know it is "hoisted" to the beginning of the function anyway, and will initialize a few lines down below, then just use
var foo;
which makes foo
undefined
. Otherwise, if you need to do anything with foo
being an object before your initialization, then it will be better to use
var foo = {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With