Numerical variables

Introduction

Variable assignment and data types

x = 1;

undefined

null

boolean

"number", other sort of number?

"var" keyword and strict

Following will run, but the typo no noticed.

myVariable = 1;
myVaraible = myVariable + 1;

We can enforce declaration of variables to help prevent this.

"use strict"
var x = 1;
x = 1;

"let" keyword and block scope

This works, even though we may not expect it to.

{
    var x = 1;
}
var y = x;

Block requires "let"

{
    let x = 1;
}
var y = x;

"let" is a newer keyword than "var". Broadly "use strict" and "let" should be used throughout.

"const" keyword

Like let (uses block scope) but can’t reassign. This increases safety and can make compiler work better.

Dynamic typing

Dynamically typed. eg can add different types of numerical stuff?

Relations

a==b 
a!=b

returns boolean

if different types, converts before comparing

"1" == 1 // evaluates to true

If use \(3\) equals signs, no type conversion.

"1" === 1 evaluates to false