Literal Type to Narrow Primitive Type
In this lesson, you will see how string and number literals are different from conventional strings and numbers.
Literal type
A literal type means that the value is an exact one. For example, a string literal of “test” would mean that the value of the variable can only be “test”.
A literal type can be made up of multiple types or values from primitive JavaScript types.
String literals
A string literal is a way to define a string that limits the potential values to be used. It’s used mostly with a union, which allows specifying more than one string value. Imagine that you allow several strings’ values but want to limit the choice to specific ones. You could use an enumeration, but a ...