Updating Variables

Updating Variables

  • We can provide variables with a value by updating a value to the variable

  • An = (equal sign) is used to assign a value to variable

  • This process of updating/changing variable’s value is also referred to as assigning a value to a variable

// declaring a variable

let firstName;


// assigning a value to the variable

firstName = "Cletus";



Declaring & Assigning Variables in one step

  • We can both declare and assign variables in one step

  • This would be done if the developer wanted to set the initial value of the variable

// declare and assign an intial value to a variable

let score = 0;


Changing the value of a Variable after an initial value has already been assigned

  • In this case we will still use a single = (equal sign) to change or reassign a value of a variable

// declare and assign a value of 0 to the score variable
let score = 0;

// changing the value of the score variable from 0 to 3
score = 3;