As someone who is new to programming I've really struggled with the idea of literals. Explanations often assume that you already know all about types and constructors. So this is my (over)simplified take on it:
By 'type', we mean the classification of the variable (different types of variables can do different things). It's common to talk about primitive-type literals such as strings, numbers, and booleans. Here is a string literal example:
let myStr = 'word';
In this case word
is a string literal; you have created something that is literally of the string type.
In JS you can have object literals as well. That is you can just type out this thing between curly braces and it is automatically a thing of object-type.
let mylitteralObject = {};
We have created an object without using an operator (an operator is essentially a built in function using familiar syntax, like '+'). The JS engine looks at the curly braces and works out that you are declaring an object.
A non literal way is to use an object constructor - a function that is combined with the new
keyword to make a new object.
let myConstructedObject = new Object();
Here the new key word is treated as an operator. And as such, the data inside myConstructedObject
is the result of an expression evaluation.