Skip to content

Instantly share code, notes, and snippets.

@jennymaeleidig
Last active December 12, 2024 15:16
Show Gist options
  • Select an option

  • Save jennymaeleidig/5101a4823c3634938b04e23c560058bc to your computer and use it in GitHub Desktop.

Select an option

Save jennymaeleidig/5101a4823c3634938b04e23c560058bc to your computer and use it in GitHub Desktop.

Double Quotes "

Good for simple strings.

var text = "Hello!";
console.log(text);

Output:

Hello!

Can be used to include single quotes.

var text = "How's it going?";
console.log(text);

Output:

How's it going?

You can also include double quotes in double quotes!, however they must be escaped (prefixed) by a backslash \.

var text = "\"What's going on?\"";
console.log(text);

Output:

"What's going on?"

Single Quotes '

Also good for simple strings!

var text = 'What?';
console.log(text);

Output:

What?

You can put doubles in singles!

var text = '"Oh!"';
console.log(text);

Output:

"Oh!"

And conversely to doubles, you can put singles in singles, but they need to be escaped as well.

var text = '\'Right!\'';
console.log(text);

Output:

'Right!'

Back Ticks `

The most powerful of the three, can be used for simple strings as well.

var text = `I am teaching margo about syntax stuff`;
console.log(text);

Output:

I am teaching margo about syntax stuff;

What makes it powerful? You can insert variables directly into the string!

var lovely_individual = "Margo";
var text = `Hello, ${lovely_individual}!`;
console.log(text);

Output:

Hello, Margo!

Of course, you can escape these as well

var text = `I am not \`quite\` sure when you would need this.`;
console.log(text);

Output:

I am not `quite` sure when you would need this.

Puttin it all together

Now for the magic!

To get some properly formatted quotes for writing....

var text = `“here’s an example,” he said.`;
console.log(text);

Output:

“here’s an example,” he said.

Hope this helps! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment