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.
2. Boolean Literals
Only two values: true
and false
. These are different from the primitive types.
3. Floating-point Literals
Essentially numbers with decimal points, but can also include exponents (similar to scientific notation) 3.2e12
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:
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
Practice
In
literals.js
, create an array literal with 3 items and an object literal with 3 values.Convert the hexidecimal number ee to base 10 (decimal). Hint: 0e = 15
Last updated