''
represents a string.
{}
symbolizes an object.
These are examples of using literal syntax to define data types with initialized values. This approach is commonly used in JavaScript for data definition.
The first example creates an empty string
. The double quotation marks are used to signify the starting and ending points of the string and do not become part of the actual data.
Strings in JavaScript are immutable, meaning you cannot append characters to an existing string, but you can replace it with a new string.
An instance of a string initialized with characters would be:
var question = "Who is John Galt?";
The resulting string contains the characters within the quotation marks, with the quotes themselves not being part of the string.
The second example creates an object
with no properties. The curly braces are used to represent the start and end of the object's literal syntax and are not related to the data within the object.
Objects in JavaScript can be modified (unless under specific circumstances not discussed here), allowing you to add properties to the object in various ways.
An example of an object with properties initialized would be:
var person = {
firstName: "John",
lastName: "Galt"
};
The resulting object contains two properties and inherits others. The properties consist of key/value pairs, where the key is usually a string (although property identifier syntax was used here), and the value can be any JavaScript data type (in this case, string literal syntax for string values).