Define var of type

I want to define an unexposed variable so I use in the initialize func the phrase

var somObject.

this var should be populated later on by an entity.
the question is, can I define the var as an entity already? or is it generic till its actually populated?

JS is a dynamically typed language so variables don’t really have a set type. They are whatever is assigned to it.

eg:

var foobar; // undefined
foobar = 10; // foobar is now a number
foobar = "asdsadas"; // foobar is a now a string
foobar = true; // foobar is a boolean

so if i want to get a script and activate some func i just do it as if it was already defined as entity (but no auto-completion will be there for me)… and if i assign differently i just deal with the runtime error?

The standard practise is to have variables be assigned to one type only (even though the language allows the programmer to switch types) and if it’s possible for it to be be undefined, check for that first.

In this particular case, I normally assign a default value such as null.

1 Like