Basic data types

suggest change

Numbers

Numbers are 8 byte, floating-point.

index.js

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

Source and playground

Output:

54.53

Strings

Strings are Unicode.

index.js

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

Source and playground

Output:

my message

Arrays

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

index.js

// :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

Output:

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.

index.js

// :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

Output:

firstName: John
lastName: Doe
hello from log()

Functions

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

index.js

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

Source and playground

Output:

hello

Dynamic typing

The same variable can be assigned values of different types.

index.js

let v;
console.log(v);

v = 5;
console.log(v);

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

Source and playground

Output:

undefined
5
str

Feedback about page:

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



Table Of Contents