fullstack_webdev

Code and notes from Full stack web developer path, LinkedIn Learning.

View on GitHub

06. Variables: Containers for Everything

06_01 Variables


06_02 Var & 06_03 Scope

var x = 4,
  y = 5,
  z = "blue";
// creates 3 variables with values provided to them

var empty;
// create undefined variables which have nothing in them, empty returns undefined i.e. it is there but something needs to be put inside it.
var x = 1;

if (x === 1) {
  var x = 2;
  console.log(x); // prints 2
}
console.log(x);
// expected output: 2

06_04 Let

-

let x = 1;

if (x === 1) {
  let x = 2;

  console.log(x);
  // expected output: 2
}

console.log(x);
// expected output: 1

06_05 Const


06_06 Data Types


06_07, 06_08 Assignment vs Comparison and Math Operators


Wrap Up

  1. What does a single equals symbol in JavaScript indicate?
  1. What happens if you use a named variable without first declaring it using the var, let, or const keywords?
  1. What is the value of defaultColor when it is logged in the console?
var defaultColor = "purple";

function setColor() {
  if (defaultColor === "purple") {
    let defaultColor = "orange";
  }
}

setColor();
console.log(defaultColor);
  1. How do you capture the result of a math equation like 42 * 38 in JavaScript?
  1. In what scenario should you use var instead of let to define a variable?
  1. Which statement is true?
  1. What is logged in the console after this code is executed?
let sum = 23.95;
let tip = "3";

console.log("The total is $" + sum + tip + ".");
  1. What is the do the operators (equals symbols) in these three lines of code signify?
a = b;
a == b;
a === b;