Mastering data types

JavaScript has a pack of built-in types. There are strings, numbers, dates, arrays, objects etc.

This section is about main types and their special features.

String

  1. String creation
  2. Methods and properties
  3. Comparison
  4. Summary

The String is by far one of the most used type in JavaScript.

There are programming languages that differ “chars” from “strings”. But in JavaScript, there are only strings, no chars. That really makes life simpler.

Another feature is that internally all strings are unicode, no matter which encoding is used.

Objects

  1. Creating objects
  2. Non-existing properties, undefined
  3. Checking if a key exists
  4. Iterating over keys-values
  5. Object variables are references
  6. Properties and methods
  7. The constructor function, “new”
  8. Built-in Objects
  9. Summary

Objects in JavaScript are kind of two-faced.

From one side, an object is an associative array (called hash in some languages). It stores key-value pairs.

From the other side, objects are used for object-oriented programming, and that’s a different story.

In this section we start from the first side and then go on to the second one.

Conversion, toString and valueOf

  1. String conversion
    1. The algorithm of Object to String conversion
    2. Custom toString
  2. Numeric conversion
    1. Custom valueOf example
  3. Conversion in equality/comparison tests
  4. Boolean context
  5. Summary

Objects in JavaScript can be converted to primitives in three contexts:

  1. Numeric
  2. String
  3. Boolean

Understanding the way conversion works helps to evade possible pitfalls and write cleaner code.

Tutorial

Donate

Donate to this project