Basic JavaScript - Understanding Uninitialized Variables

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

// Only change code below this line
var a;
var b;
var c;
// Only change code above this line

a = a + 1;
b = b + 5;
c = c + " String!";

var a = 6
var b = 15
var c = c + "I am a String";

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Understanding Uninitialized Variables

Link to the challenge:

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

I see where are you’re struggling.

In JavaScript, variables can be Declared, Defined,Uninitialized and Initialized(let me explain this programming terminology)

Declared:
We say a variable is declared when you’ve given a name to a variable, but you haven’t assigned it a specific value yet. For example:

let a;  // It's a variable called "a"

A variable has two states, Uninitialized or Initialized

Uninitialized:
It’s when we created a variable, however we don’t give a value to it, for example:

let b;  // it's a variable called "b", however doesn't have any value

Initialized:
Is the opposite of Uninitialized, we say that a variable is Initialized when we give value to the declared variable, for example:

var c; //  We declare the variable called "c" (set a variable with a name but without a value)

c = 55; // Initialization of the variable "c" (meaning, giving a value to it), see that we don't need to add the prefix `var` again, because it's already set above

Defined:
Last, we say that a variable is defined when we declare and Initialize in a single step, for example:

var d = 55; // we created the variable "d" and initialized with a value of 55 at the same time

So having this concepts clear, we can take a look at your problem.

The lesson " Understanding Uninitialized Variables" gives you this piece of code:

// Only change code below this line
var a;
var b;
var c;

// Only change code above this line
a = a + 1;
b = b + 5;
c = c + " String!";

The first part:

var a;
var b;
var c;

As you can see, the code provides three variables with no values (how do we call these?)

a = a + 1;
b = b + 5;
c = c + " String!";

In the last part of the code, we can see that it doesn’t use the prefix var meaning that it’s already set

So the lesson asks you:

  • Initialize the three variables a, b, and c (It doesn’t say add new variable but Initialize the existing ones)
  • Add the values 5, 10, and "I am a" respectively, so the initial value of the variables doesn’t equal to undefined.

Try solving it and let me know if you have any problem

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.