Skip to content

Instantly share code, notes, and snippets.

@tbsvttr
Created December 29, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbsvttr/86cf033443055f0aa44f7102f346adba to your computer and use it in GitHub Desktop.
Save tbsvttr/86cf033443055f0aa44f7102f346adba to your computer and use it in GitHub Desktop.
// Usage of quotes as wrappers of string literals an within those string literals
var name = 'Tobias'; // String literal wrapped in single quotes.
var planet = "Earth"; // String literal wrapped in double quotes.
// Usage of single quotes within a string literal wrapped in double quotes.
var firstQuote = "They said the product is 'good'.";
// Usage of double quotes within a string literal wrapped in single quotes.
var secondQuote = 'They said the product is "good".';
// Those would not work (without escaping)
var firstQuote = 'They said the product is 'good'.';
var secondQuote = "They said the product is "good".";
// Usage of the escape character
var doubleQuote = "\""; // Gives a string literal with one double quote in it.
var singleQuote = '\'';
var backslash = '\\';
var slash = '\/';
var backspace = '\b';
var formfeed = '\f';
var newline = '\n';
var carriageReturn = '\r';
var tab = '\t';
var verticalTab = '\v';
var unicodeCodepoint = '\uXXXX';
var nullCharacter = '\0';
// Template literals, added in ECMAScript 2015, using backticks instead of quotes.
var text = `hello world`
var text = `hello!
world!`
var who = 'Tobias'
var text =`hello ${who}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment