JS-101-Fundamentals
  • JavaScript Library
  • 1-JavaScript Fundamentals
    • 0-Getting Started
      • Welcome
    • 1-JS-Fundamentals
      • 1-Grammar and Types
        • Comments
        • Declarations
        • Scope
        • Hoisting
        • Types
        • Literals
      • 2-Control Flow and Error Handling
        • if
        • if else
        • switch
        • try catch
        • throw
      • 3-Loops
        • For Loops
        • For In Loops
        • For Of Loops
        • Do While
        • While Loops
      • 4-Functions
        • Declarations
        • Expressions
        • Calling Functions
        • Scope
        • Parameters
        • Arguments
        • Closures
        • Closures Challenge
        • Arrow Functions
        • Predefined
      • 5-Expressions and Operators
        • Assignment
        • Comparison
        • Ternary
        • Typeof
        • Left Hand Side
        • Spread
      • 6 Numbers and Dates
        • Numbers
          • Numbers Enhanced
        • Math
        • Dates
      • 7 String Methods
        • String Literals
        • Methods
      • 8 Regular Expressions
        • Basic Intro
      • 9 Arrays
        • Array Review
        • Populating/Referring
        • Length
        • Iterating
        • Methods
      • 10 Objects
        • About Objects
        • Properties
        • Enumeration
        • Initializers
        • Constructor Functions
        • this
        • create
        • Methods
      • 11 ES6 Intro
        • ES6 Intro
        • let
        • const
Powered by GitBook
On this page
  • 1. Array Literals
  • 2. Boolean Literals
  • 3. Floating-point Literals
  • 4. Integers
  • 5. Object Literals
  • 6. RegExp Literals
  • 7. String Literals
  • File Location
  • Practice
  1. 1-JavaScript Fundamentals
  2. 1-JS-Fundamentals
  3. 1-Grammar and Types

Literals

Literals are fixed values within JavaScript. Rather than assigning these values like variables, you insert values directly into the literal. There are seven types of literals within JavaScript:

1. Array Literals

An array is a group of values, indicated by square brackets [ ] using commas , to separate the values.

var players = ["Steph Curry", "Kevin Durant", "Klay Thompson"];

2. Boolean Literals

Only two values: true and false. These are different from the primitive types.

var happy = true;

3. Floating-point Literals

Essentially numbers with decimal points, but can also include exponents (similar to scientific notation) 3.2e12

4.1, 5.5, 10.1

4. Integers

Literally numbers. Can appear in multiple forms: Base 10 (0-9), Base 8 (octal; 0-7), Base 16 (hexidecimal; 0-e), or Base 2 (binary; 0-1)

5. Object Literals

Similar to the object data-type. Example:

let x = { a:0, b:1, c:2 }
console.log(x.a)// 0
console.log(x.b)// 1
console.log(x.c)// 2

6. RegExp Literals

RegExp will be explained further later. It is a pattern within slashes, like this: /ab+c/

7. String Literals

A set of characters within either single quotation marks ( ' ) or double quotation marks ( " ). Either can be used for a string, but they cannot be used together. Examples: 'hello', "hello"

File Location

    javascript-library
        └── 1-Fundamentals
            └── 1-Grammar-and-Types
                06-literals.js <-- You are here

Practice

  1. In literals.js, create an array literal with 3 items and an object literal with 3 values.

  2. Convert the hexidecimal number ee to base 10 (decimal). Hint: 0e = 15

PreviousTypesNext2-Control Flow and Error Handling

Last updated 7 years ago