Basic data types

suggest change

Numbers

The Number type is a 64-bit IEEE 754 floating-point value (8 bytes), not a separate integer type. BigInt is a different type and is not covered here.

// :glot
const i = 16;
const j = 38.53;
const z = i + j;
console.log(z); // -> 54.53

Source and playground

54.53

Strings

Strings are sequences of UTF-16 code units. A single Unicode code point may take one or two units.

// :glot
let s = "my";
s = s + " message";
console.log(s); // -> my message

Source and playground

my message

Arrays

Arrays can grow and shrink and elements can be of any type.

// :glot
const cars = ["Model 3", "Leaf", "Bolt"];
console.log("first car:", cars[0]);

const mixedTypes = ["string"];
mixedTypes.push(5);
console.log("array with mixed types:", mixedTypes);

Source and playground

first car: Model 3
array with mixed types: [ 'string', 5 ]

Objects (dictionaries, hash tables)

Objects map keys to values. In other languages they are known as dictionaries or hash tables. Values can be of any type, including functions.

// :glot
const person = {
	firstName: "John",
	lastName: "Doe",
	log: () => console.log("hello from log()")
};
console.log("firstName:", person.firstName);
console.log("lastName:", person["lastName"]);
person.log();

Source and playground

firstName: John
lastName: Doe
hello from log()

Functions

Functions are first-class meaning they can be assigned to variables and passed around.

const logMe = function(s) {
	console.log(s);
}
const logMe2 = logMe;
logMe2("hello");

Source and playground

hello

Dynamic typing

The same variable can be assigned values of different types.

let v;
console.log(v);

v = 5;
console.log(v);

v = "str";
console.log(v);

Source and playground

undefined
5
str

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents