HomeWHICHWhich Of The Following Statements Does Not Reflect Proper Grammar

Which Of The Following Statements Does Not Reflect Proper Grammar

A string literal is zero or more characters enclosed in 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).

The following are examples of string literals:

You should use string literals unless you specifically need to use a String object. See String for details on String objects.

You can call any of the String object’s methods on a string literal value. JavaScript automatically converts the string literal to a temporary String object, calls the method, then discards the temporary String object. You can also use the length property with a string literal:

Template literals are also available. Template literals are enclosed by the back-tick (`) (grave accent) character instead of double or single quotes.

Template literals provide syntactic sugar for constructing strings. (This is similar to string interpolation features in Perl, Python, and more.)

Tagged templates are a compact syntax for specifying a template literal along with a call to a “tag” function for parsing it. A tagged template is just a more succinct and semantic way to invoke a function that processes a string and a set of relevant values. The name of the template tag function precedes the template literal — as in the following example, where the template tag function is named print. The print function will interpolate the arguments and serialize any objects or arrays that may come up, avoiding the pesky [object Object].

Refer to more articles:  Which Kpi Is A Vanity Metric

Since tagged template literals are just sugar of function calls, you can re-write the above as an equivalent function call:

This may be reminiscent of the console.log-style interpolation:

You can see how the tagged template reads more naturally than a traditional “formatter” function, where the variables and the template itself have to be declared separately.

Using special characters in strings

In addition to ordinary characters, you can also include special characters in strings, as shown in the following example.

The following table lists the special characters that you can use in JavaScript strings.

Escaping characters

For characters not listed in the table, a preceding backslash is ignored, but this usage is deprecated and should be avoided.

You can insert a quotation mark inside a string by preceding it with a backslash. This is known as escaping the quotation mark. For example:

The result of this would be:

He read “The Cremation of Sam McGee” by R.W. Service.

To include a literal backslash inside a string, you must escape the backslash character. For example, to assign the file path c:temp to a string, use the following:

You can also escape line breaks by preceding them with backslash. The backslash and line break are both removed from the value of the string.

RELATED ARTICLES

Most Popular

Recent Comments