Last active
December 21, 2015 01:29
-
-
Save j201/6227909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript's strings aren't multiline by default | |
var poem = "old pond . . . | |
a frog leaps in | |
water’s sound"; | |
// SyntaxError: unterminated string literal | |
// You can get multiline strings by escaping the newline... | |
var poem = "old pond . . . \ | |
a frog leaps in \ | |
water’s sound"; | |
// "old pond . . . a frog leaps in water’s sound" | |
// But you need \n to represent newlines | |
var poem = "old pond . . . \n\ | |
a frog leaps in \n\ | |
water’s sound"; | |
/* "old pond . . . | |
a frog leaps in | |
water’s sound" */ | |
// And characters after the slash will break it | |
var poem = "old pond . . . \n\ | |
a frog leaps in \n\ | |
water’s sound"; | |
// SyntaxError: unterminated string literal | |
// Another way is to use the + concatenation operator, which avoids that problem | |
// and allows you to align the lines without adding whitespace | |
var poem = "old pond . . . \n" + | |
"a frog leaps in \n" + | |
"water’s sound"; | |
/* "old pond . . . | |
a frog leaps in | |
water’s sound" */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment