Javascript variable rules in short

  •  Javascript varibles have 5 types: number, string, boolean, undefined and null.
  • string, number and boolean types have wrapper objects.
  • var a = “str”; is a primitive String.
  • var a = new String(“str”); is a String object.
  • When an object property is needed, like the length or toUppercase, Javascript runtime creates a temporary object to do the job.
  • A Javascript variable type is dynamic. With ‘typeof’ operator, the current type of an operator can be found.
  • A variable declaration is mandatory for read actions but optional for write operations.
  • Objects returns “undefined” for not existing properties.
  • a=3; // write operation. We write value 3 to variable a
  • var b = a; // read and write operation. We read value from a and write to b
  • var b = c; // exception: c is undeclared. A variable has to be declared for read operations

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s