Skip to content

Latest commit

 

History

History
60 lines (52 loc) · 1.8 KB

File metadata and controls

60 lines (52 loc) · 1.8 KB

JavaScript Types

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

Object type is a collection of name/value pairs. Look at the example below;

firstName: "Musa",
lastName: "Toktas",
socialMedia: {
   linkedin: "musatoktas",
   twitter: "mtoktas41"
   }

Primitive Types

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

  1. Boolean
  2. 2 values: True or False, reserved keywords.

  3. Undefined
  4. 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.

  5. Null
  6. Signifies lack of value.
    • As opposed to undefined, which is lack of definition
    • Can only one value: null
    • It's ok to explicitly set a variable to null

  7. Number
  8. The only numeric type in JS.
    • 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

  9. String
  10. Sequence of characters used to represent text
    • Using single or double quots are allowed, i.e., 'text' or "text"

  11. Symbol
  12. New to ES6
    • EcmoScript6(released 2015) isnt widely supported or used yet