DEV Community

Cover image for LEVEL UP with JavaScript! LVL 4
DevCronin
DevCronin

Posted on • Edited on

LEVEL UP with JavaScript! LVL 4

In this blog series tutorial, I will be covering some of the basic JavaScript programming concepts.

This is geared toward beginners and anyone looking to refresh their knowledge.

See the Previous Level Here

Level 4 will cover:

  • Declare String Variables
  • Escaping Literal Quotes in Strings
  • Quoting Strings with Single Quotes
  • Escape Sequences in Strings
  • Concatenating Strings with Plus Operator

Declare String Variables

A string variable is when zero or more characters are enclosed in quotes.

Numbers can also be a string if enclosed in quotes.

let character = "Tempest Cleric"

Enter fullscreen mode Exit fullscreen mode

Escaping Literal Quotes in Strings

Escaping literal quotes is used when you need to use quotes inside of the quotes of the declared string.

This is done using a backslash before both of the actual quotations.

let magicAxe = "Greataxe \"of the Brute\""; 

console.log(magicAxe)

Greataxe "of the Brute"

Enter fullscreen mode Exit fullscreen mode

Quoting Strings with Single Quotes

When quoting, single quotes or double quotes may be used.

If this is done, care needs to be taken to avoid ending the string with a non-paired single quotation character.

Again the backslash can be used before the quotation character to escape it and prevent the error.

let myTeam = 'The paladin said "I am the strongest"!'

console.log(myTeam)

The paladin said, "I am the strongest"!

Enter fullscreen mode Exit fullscreen mode

Escape Sequences in Strings

There are also some special characters that we need to use the backslash to escape.

When we do this, make sure not to add any spaces between escape sequences or words.

Below is a list of some of these possible characters;

\' single quote
\" double quote
\ backslash
\n newline
\r carriage return
\t tab
\b word boundary
\f form feed

var character = "Druid\nLevel One";

console.log(character)

Druid
Level One

Enter fullscreen mode Exit fullscreen mode

Concatenating Strings with Plus Operator

Concatenating strings use the (+) concatenate operator to add strings together. This is used to build a new string. There will be no spaces unless specifically added.

var character = "Moon " + "Druid"; 

console.log(character)

Moon Druid

Enter fullscreen mode Exit fullscreen mode

Thank you for reading my blog! This is the Fourth of my series on JavaScript so if you would like to read more, please follow!

See the Next Level Here

Support and Buy me a Coffee

Top comments (0)