Stay-Hack06 / js-variables-activities

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variables in JavaScript

Background

Declaring A Variable
  • Declaring a variable in JavaScript is the process of creating a container to store data. Variables allow you to hold values of various types, such as numbers, strings, booleans, arrays, objects, and more. They provide a way to store data temporarily in memory so that you can use and manipulate it later in your code.

  • To declare a variable in JavaScript, you use the let or const keyword (var is also a keyword that can be used, sparingly) followed by the variable name. The syntax for declaring a variable is as follows:

let userAge;
const daysOfTheWeek;
Assigning A Variable
  • Assigning a variable in JavaScript means giving it a value. Once you declare a variable, you can assign a specific value to it or update its value at any time during the execution of your code.

  • To assign a value to a variable in JavaScript, you use the assignment operator (=). The syntax for assigning a variable is as follows:

let userAge = 43;
let userName = "Colin";
const PI = 3.14159;
  • Assigning values to variables:
userAge = 25;
userName = "Marc Antony";
  • Variables can be assigned different values later:
let name = "Colin";
let age = 29;

age = 30;
name = "Cleopatra";
  • Constants are assigned a value when declared—they can't be reassigned new values, so the only way they get a value is when they're declared.
const daysInWeek = 7;

Activities

Prep
  1. Connect your js file to your HTML file
  2. Open your code in the browser (directly or via Live Server) and open your console
Exercise 1
  1. Look at the figma_design file in the assets folder of this repo.
  2. List all of the possible variables that exist on the page, and declare them as variables.
Exercise 2

Declaring variables is an important way to work with data in your JavaScript file.

Follow the instructions in the scripts.js file for Declaring Variables.

Exercise 3

You will need to be able to reassign the values of a variable. This can be helpful when working with different datasets.

  1. Take the strings listed and make sure that they are formatted property.
  2. Follow the instructions in th scripts.js file for Reassigning Variables.
Exercise 4

This exercise will have you working with const.

Follow the instructions in th scripts.js file for Working With Constants.

About


Languages

Language:JavaScript 87.0%Language:HTML 13.0%