Basic data types

suggest change

Numbers

Numbers are 8 byte, floating-point.

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

Strings

Strings are Unicode.

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

Arrays

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

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);
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.

const person = {
	firstName: "John",
	lastName: "Doe",
	log: () => console.log("hello from log()")
};
console.log("firstName:", person.firstName);
console.log("lastName:", person["lastName"]);
person.log();
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");
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);
undefined
5
str

Feedback about page:

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


Basic data types:
* Arrays

Table Of Contents
2 Basic data types
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde