Javascript - Data Types


There are 6 primative types in JavaScript.

  • string
  • number
  • bigint
  • boolean
  • undefined
  • symbol

null is a special primative like type.

object is a more complex data structure.

Bigint

BigInt is used to hold large integer values.

const a = 123456789012345n;
const b = BigInt(678967896789678678);

Boolean

Boolean has two values true or false.

Null

null means "nothing" or "empty".

var num = null;

Number

Number in html is a 64-bit floating point number.

var x = 3.14;

There are three special numeric values for Numbers: Infinity, -Infinity, and Nan

Object

An object in JavaScript is similar to a class in C++.

var person = {
    firstName: "Dalton",
    middleName: "Russell",
    lastName: "Cole",
    fullName: function() {
        return `${firstName:} ${middleName:} ${lastName:}`;
    }
}; // <- DON'T FORGET THE ;

String

There are three string quote options in JavaScript:

  1. Double quotes: "Hello"
  2. Single quotes: 'Hello'
  3. Backticks: `Hello`

Double and single quotes behave identically. Backticks allow code to be embedded into a string via ${...} wrapping.

var str = "Hello World";
var str2 = 'Hola Mundo';
var str3 = `English: ${str}, Spanish: ${str2}`
var str4 = `${1 + 2}`; // '3'

Escape sequences:

  • Hexadecimal: '\xA9'
  • Unicode: '\u00A9' or '\uP00A9'

Undefined

undefined means "value is not assigned". Variables are undefined before they are assigned.

var num; // undefined