Uninitialized JavaScript variables.

Uninitialized JavaScript variables.

·

1 min read

Let's consider this example ;

var a;
let b;
console.log('a = ' + a);
console.log('b = ' + b)

In this example we have variables a and b defined with var and let but without the equal sign. This brings up an undefined output in the console meaning a variable that doesn’t yet have a value (Uninitialized variable). UNDEFINED IS A VERY IMPORTANT KEYWORD IN JS.

Another example is;

a = 12;
b = 34;
console.log('a = ' + a)
console.log('b = ' + b)

This outputs;

12 and 34 respectively. It's important to note that when we assign variables without specifying var or let, we make this variable automatically global. This means it can be used anywhere in the program. It's strongly advisable to use as few global variables in the program, as this complicates the design and debugging of the programs that contain them.