GithubHelp home page GithubHelp logo

js-variables-activities's Introduction

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.

js-variables-activities's People

Contributors

anntech21 avatar abbreviatedman avatar lhack47 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.