Javascript Literals
Instructions
- 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
- 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
- In a separate file, record:
- the literal example;
- the line(s) of code you found it in;
- a link to the original source (if available).
Example Literals
String
"demo"
- line:
document.getElementById("demo").innerHTML = x;
- source
- line:
Number
6
- line:
x = 6;
- source
- line:
Boolean
true
- line:
assert.ok(config.setSepChr('/') === true);
- source
- line:
Null
null
- line:
if ( data == null && fn == null ) {
- source
- line:
Array
['generateLabels', 'filter', 'sort']
- line:
_scriptable: (name) => !['generateLabels', 'filter', 'sort'].includes(name),
- source
- line:
Object
{
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}
line:
const htmlEscapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}
Function
function(width, height) {
return width * height;
}
line:
const getRectArea = function(width, height) {
return width * height;
};