Skip to content

Just Javascript #20

@8bitzz

Description

@8bitzz

Reference: Just Javascript course

Values and Code

Primitive Values

  • They are a permanent part of our JavaScript universe. I can point to them, but I can’t create, destroy, or change them.
  1. Undefined (undefined), used for unintentionally missing values.
  2. Null (null), used for intentionally missing values.
  3. Booleans (true and false), used for logical operations.
  4. Numbers (-100, 3.14, and others), used for math calculations.
  5. BigInts (uncommon and new), used for math on big numbers.
  6. Strings ("hello", "abracadabra", and others), used for text.
  7. Symbols (uncommon), used to perform rituals and hide secrets.

Objects and Functions

  • Objects and functions are also values but, unlike primitive values, I can manipulate them from my code.
  1. Objects ({} and others), used to group related data and code.
  2. Functions (x => x * 2 and others), used to refer to code.

Expressions

  • We can ask questions with expressions.
  • Expressions exist in our code, so they are not values. Rather, JavaScript will answer our expressions with values.

Values and Variables

Primitive Values Are Immutable

  • They’re a permanent part of our JavaScript universe—we can’t create, destroy, or change them.
  • For example, we can’t set a property on a string value because it is a primitive value.
let fifty = 50;
fifty.shades = 'gray'; // No!
  • Arrays are not primitive, so we can set their properties.
let arr = [212, 8, 506];
let str = 'hello';
arr[0] = 420;
console.log(arr); // [420, 8, 506]

Variables are not values

  • Each variable points to a particular value.
  • We can change which value it points to by using the = assignment operator.

Variables Are Wires

  • A “wire” is not a JavaScript concept—but it helps us imagine how variables point to values.
  • When we do an assignment, there’s always a wire on the left, and an expression (resulting in a value) on the right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions