All technological notes.
primitive value
3.14 is a primitive value.
Primitive values are immutable (they are hardcoded and cannot be changed).x = 3.14, you can change the value of x, but you cannot change the value of 3.14.primitive data type
primitive value.JavaScript defines 7 types of primitive data types:
Object contain values
A JavaScript variable can hold any type of data.
// Numbers:
let length = 16;
let weight = 7.5;
// Strings:
let color = "Yellow";
let lastName = "Johnson";
// Booleans
let x = true;
let y = false;
// Object:
const person = { firstName: "John", lastName: "Doe" };
// Array object:
const cars = ["Saab", "Volvo", "BMW"];
// Date object:
const date = new Date("2022-03-25");
When adding a number and a string, JavaScript will treat the number as a string.
let x = 16 + "Volvo"; //16Volvo
let x = "Volvo" + 16; //Volvo16
let x = 16 + 4 + "Volvo"; // 20Volvo
let x = "Volvo" + 16 + 4; // Volvo164
JavaScript Types are Dynamic
let x; // Now x is undefined
x = 5; // Now x is a Number
x = "John"; // Now x is a String
typeof Operatortypeof ""; // Returns "string"
typeof "John"; // Returns "string"
typeof "John Doe"; // Returns "string"
typeof 0; // Returns "number"
typeof 314; // Returns "number"
typeof 3.14; // Returns "number"
typeof 3; // Returns "number"
typeof (3 + 4); // Returns "number"
Strings are written with quotes. You can use single or double quotes.
// Single quote inside double quotes:
let answer1 = "It's alright";
// Single quotes inside double quotes:
let answer2 = "He is called 'Johnny'";
// Double quotes inside single quotes:
let answer3 = 'He is called "Johnny"';
All JavaScript numbers are stored as decimal numbers (floating point).
Numbers can be written with, or without decimals
Exponential Notation
let y = 123e5; // 12300000
let z = 123e-5; // 0.00123
All JavaScript numbers are stored in a a 64-bit floating-point format.
JavaScript BigInt is a new datatype (2020) that can be used to store integer values that are too big to be represented by a normal JavaScript Number.
Booleans can only have two values: true or false.
Booleans are often used in conditional testing.
JavaScript arrays are written with square brackets.
Array items are separated by commas.
Array indexes are zero-based, which means the first item is [0], second is [1], and so on.
const cars = ["Saab", "Volvo", "BMW"];
JavaScript objects are written with curly braces {}.
Object properties are written as name:value pairs, separated by commas.
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue",
};
undefined. The type is also undefined.let car; // Value is undefined, type is undefined
let car = "Volvo";
car = undefined; //undefined
typeof car; //undefined