A type is a particular data structure.
- Each lang. defnes some built-in types.
- Built-in types can be used to build other data structures.
- JS has 7 built-in types: 6 primitive and 1 object type.
Object type is a collection of name/value pairs. Look at the example below;
firstName: "Musa",
lastName: "Toktas",
socialMedia: {
linkedin: "musatoktas",
twitter: "mtoktas41"
}
Primitive type represents a single, immutable value
- Single value, i.e., not an object
- Immutable means once it's set, it can't be changed
- Value becomes read-only
- You can create another value based on an existing one
-
2 values: True or False, reserved keywords.
Signifies no value has ever been set.
- Can only have one value: undefined,
- You can set a variable to undefined, but you should NEVER do it
- meaning is that its never been defined, so defining it to undefined is counter to its core meaning.
- As opposed to undefined, which is lack of definition
- Can only one value: null
- It's ok to explicitly set a variable to null
- Always represented under the hood as double-precision 64-bit floating point
- JS doesnot have an integer type
- Integers are subset of doubles instead of a seperate data type
- Using single or double quots are allowed, i.e., 'text' or "text"
- EcmoScript6(released 2015) isnt widely supported or used yet