javascript string double and single quotes interchangeably

JavaScript regular expression pattern string double and single quotation marks replaced by each other, in fact, use a String object replace () method.

var yanggb = "y'a'n'g'g'b";

Double quotes replaced by single quotes

yanggb.replace(/\"/g,"'");

Alternatively single quotes double quotes

yanggb = yanggb.replace(/\'/g, '"');
yanggb.replace(/\"/g, "'");

JSON string in the scene

This approach is often used in a JSON string scenario, you may be blended the JSON.stringify () method and the JSON.parse () method to restore JSON string special treatment.

Also special mention about the use of JavaScript string of time to pay special attention to the immutability of strings, such as modifying the string to be re-assigned to a variable, or it may occur illusion to modify the source string is not in force but how .

 

"To a man buried many secrets in order to skillfully through life."

Guess you like

Origin www.cnblogs.com/yanggb/p/12122655.html