Does it cause problems if I don't set empty variables according to their data type but to null?

Viewed 49

With placeholder variables which are to be filled later with data from a database you can obviously do it in both ways. The only question is, are there any circumstances in which JavaScript treats null differently than an array with no elements or an object with no properties?

Does JavaScript ever treat:

let userdetails = null

differently from either:

let userdetails = {}
//or
let userdetails = []
1 Answers

it's pretty much your choice, but I will go with undefined rather than null because they are undefined after all and it would not confuse me during testing. But there would be no problem with null too.

Related