* very customizable in TypeScript
typeof "text";
// string
let a = null;
console.log(a);
// null
There are two features of null you should understand:
Undefined most typically means a variable has been declared, but not defined.
You can also explicitly set a variable to equal undefined:
let b;
console.log(b);
// undefined
var d = {};
console.log(d.fake);
// undefined
var u = undefined;
let a = true;
console.log(a);
// true
let b = 1;
console.log(b);
// 1
console.log(a == b);
// true
console.log(a === b);
// false
let c = false;
console.log(c);
// false
let c = 0;
console.log(d);
// 0
console.log(c == d);
// true
console.log(c === d);
// false
let a = true;
typeof a;
// boolean
let b = 1;
typeof b;
// number
let a = 123;
typeof a;
// number
let b = 12.3;
typeof b;
// number
console.log(a > b);
// true
let c = "123";
typeof c;
// string
let d = "12.3";
typeof d;
// string
console.log(c > d);
// true
let a = "John";
typeof a;
// string
let b = 'Doe';
typeof b;
// string
console.log(a + b);
// 'JohnDoe'
console.log(a + " " + b);
// 'John Doe'
let a = `John`;
typeof a;
// string
let b = `Doe`;
typeof b;
// string
console.log(`${a} ${b}`);
// 'John Doe'
typeof `123.00`;
// string
` (back-ticks)
let person = {
firstName: "John",
lastName: "Doe"
};
typeof person;
// object
typeof person.firstName;
// string
typeof window;
// object
typeof document;
// object
var hello = (name) => {
return `hello ${name}`;
}
typeof hello;
// function
class Calculator {
sum = (a, b) => a + b
}
typeof Calculator;
// function
*syntax sugar for functions
var a = Symbol('example');
typeof a
// Symbol(example)
Symbol('foo') === Symbol('foo');
// false
let mixed = Array(1, 2, 'text', {name: 'John'})
// mixed = [1, 2, 'text', {name: 'John'}] // same
typeof mixed
// object
Array.isArray(mixed)
// true
typeof mixed[0];
// number
typeof mixed[2];
// string
typeof mixed[3];
// object
typeof mixed[4];
// undefined
let user = "John Doe"
declaration
set
value
name
let user: string = "John Doe"
declaration
set
value
name
annotation
type