Literals represent values in JavaScript. These are fixed values—not variables.
Literal is in javascript
String literals: A string literal is zero or more characters enclosed in a double (
"
) or single quotation marks ('
). A string must be delimited by quotation marks of the same type (that is, either both single quotation marks or both double quotation marks).
Example: "one line \n new line";
"John's cat";
Object Literal: An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}
).
Syntex:
const sales = "BMW"; function carTypes(name) { return name === "Honda" ? name : `Sorry, we don't sell ${name}.`; }const sales = "BMW"; function carTypes(name) { return name === "Honda" ? name : `Sorry, we don't sell ${name}.`; } const car = { myCar: "Toyota", getCar: carTypes("Honda"), special: sales, }; console.log(car.myCar); // Toyota console.log(car.getCar); // Honda console.log(car.special); // BMW
Comments
Post a Comment