String Usage in JavaScript

Question
What are the correct ways to work with strings in JavaScript?

Answer
I recommend using double quotes to delimit strings even though single quotes are also permitted. In addition, avoid multi-line strings. Instead, split long strings into multiple ones and concatenate them. See the examples below.

Examples

// Not good.
let aVeryLongString = "Oh, supercalifragilisticexpialidocious! Even though the sound of it \ 
Is something quite atrocious.";

// Good.
let aVeryLongString = "Oh, supercalifragilisticexpialidocious! " + 
                      "Even though the sound of it" + 
                      "Is something quite atrocious.";

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s