Javascript Literals

Instructions

  1. Using a method of your choice, find examples of Javascript code online, for example:
    • Search "javascript examples";
    • Find your favourite Javascript library;
    • Inspect live websites
  2. Within the code you find, identify examples of literals for each of the following value types (they don't all have to be from the same example):
    • string
    • number
    • boolean
    • null
    • array
    • optional: object
    • optional: function
  3. In a separate file, record:
    1. the literal example;
    2. the line(s) of code you found it in;
    3. a link to the original source (if available).

Example Literals

String

Number

Boolean

Null

Array

Object

{
  '&': '&',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;'
}

line:

const htmlEscapes = {
  '&': '&amp;',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;'
}

Function

function(width, height) {
  return width * height;
}

line:

const getRectArea = function(width, height) {
  return width * height;
};