Skip to content

1. JavaScript

JavaScript can function as both a procedural and an object oriented language.

Web browser is the runtime environment for client-side JavaScript.

Node.js is a server side environment that is operates in a similar capacity to the JVM in java

1.1. JavaScript vs ECMAScript

  • ECMAScript/ES is a specification for a scripting language.
  • Not all browsers support all ES features

2. Printout

console.log("Hello World");

3. Variable declaration and definition

JavaScript is dynamically-typed and does not require type constraints

var myNum = 42;
myNum = "forty-two";

There are 3 keywords for declaration:

  • var - was default before ES6. But due to issues, that's why there are other ways of declaring.
    • Scope: Declared global outside function. And local when declared inside the function.
    • var variables can be re-declared and updated
    • Hoisting of var: if var is referred to before declaration. Then interpreter assumes it was assigned to undefined
    • The problem is that var can be redefined in the middle of the code, which can cause unexpected answers.
  • let - now used as the preferred variable declaration.
    • Block scoped: (A block lives in curly braces)
    • Can be updated but not re-declared
    • Those two can be combined, by redeclaring variables in blocks.
    • Hoisting of let: Just like var it can be hoisted on the top, but unlike var you get Reference Error
  • const - maintain constant values
    • Block Scoped: can only be accessed within the block they were declared
    • Cannot be updated or re-declared: Therefore it's constant
      • For a constant object, the object cannot be updated or redefined but the properties can be changed.
    • Hoisting of const: Hoisted but no initialised just like let

4. Access modifiers

There are no access modifiers like in Java, everything is accessible.

5. Primitive Types in JavaScript

  • Number - equivalent to double in Java
  • String - no such thing as a char
  • Boolean
  • Symbol - ES6 addition
  • Undefined - implicitly assigned when variable is declared but not instantiated
  • Null - Is an explicitly assigned.

6. Reference