School

Advanced Javascript

Week 01

Class

Read

  • Javascript Variables

    We can declare variables to store data by using the var, let, or const keywords. let – is a modern variable declaration. var – is an old-school variable declaration. Normally we don’t use it at all, but we’ll cover subtle differences from let in the chapter The old "var", just in case you need them. const – is like let, but the value of the variable can’t be changed. Variables should be named in a way that allows us to easily understand what’s inside them.

  • Javascript Scope

    The scope is a policy that manages the availability of variables. A variable defined inside a scope is accessible only within that scope, but inaccessible outside. In JavaScript, scopes are created by code blocks, functions, modules. While const and let variables are scoped by code blocks, functions or modules, var variables are scoped only by functions or modules. Scopes can be nested. Inside an inner scope you can access the variables of an outer scope. The lexical scope consists of the outer function scopes determined statically. Any function, no matter the place where being executed, can access the variables of its lexical scope (this is the concept of closure).

  • Javascript Variable Types

    There are 8 basic data types in JavaScript.

      Seven primitive data types:
    • number for numbers of any kind: integer or floating-point, integers are limited by ±(253-1).
    • bigint for integer numbers of arbitrary length.
    • string for strings. A string may have zero or more characters, there’s no separate single-character type.
    • boolean for true/false.
    • null for unknown values – a standalone type that has a single value null.
    • undefined for unassigned values – a standalone type that has a single value undefined.
    • symbol for unique identifiers.
    • And one non-primitive data type:
    • object for more complex data structures.
    The typeof operator allows us to see which type is stored in a variable. Usually used as typeof x, but typeof(x) is also possible. Returns a string with the name of the type, like "string". For null returns "object" – this is an error in the language, it’s not actually an object.

    Demonstrates the use of data types - strings, numbers, booleans, objects, collections which are objects, function definitions are their own datatype

Watch