Skip to main content

Command Palette

Search for a command to run...

Uninitialized JavaScript variables.

Updated
1 min read
Uninitialized JavaScript variables.
S

A Full-stack Developer based in Nairobi Kenya , with a focus on creating robust and user friendly web applications. With strong foundation in both front-end and backend development, I specialize in building responsive and scalable solutions that deliver exceptional user experiences.

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.