LEVEL UP with JavaScript! LVL 5

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.

Level 5 will cover:

Concatenating Strings with Plus Equals…


This content originally appeared on DEV Community and was authored by DevCronin

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.

Level 5 will cover:

  • Concatenating Strings with Plus Equals Operator
  • Constructing Strings with Variables
  • Appending Variables to Strings
  • Find the Length of a String
  • Use Bracket Notation to Find the First Character in a String

Concatenating Strings with Plus Equals Operator

As we did with the compounded assignment (+=) operator before, now we will use it to concatenate a string on an existing variable.

Remember, spaces only exist if we add them.

let iroh = "dragon, "; 

iroh += "of the west."; 

console.log(iroh);

"dragon, of the west"

Constructing Strings with Variables

In JavaScript, it is common to build longer, more complex strings.

To do this we will be using the concatenation operator (+) to insert one or more variables to construct the string.

let mySpell = "magic missile"; 

let spellDescription = "I cast " + mySpell + ", and three glowing darts home in on my target."; 

console.log(spellDescription)

"I cast magic missile, and three glowing darts home in on my target."

Appending Variables to Strings

Variables can also be appended to strings using the (+=) operator.


let alignment = "Chaotic "; 

let alignmentTwo = "Good";

alignment += alignmentTwo; 

console.log(alignment);

Chaotic Good

Find the Length of a String

To find the length of a string we use ".length" after the string but before the end (;).

Length is given in the number of characters start with the index of zero.

It can also be used on string variables or string literals.


let game = "Dungeons and Dragons";

let gameLength = game.length; 

console.log(gameLength);

20

Use Bracket Notation to Find the First Character in a String

In JavaScript counting starts at 0, and is referred to as Zero-based indexing.

By using bracket notation ([]) we can get any character at a specific index in a string.

let character = "Wizard"; 

let firstLetter = character[0];

console.log(firstLetter);

"W"

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

Support and Buy me a Coffee


This content originally appeared on DEV Community and was authored by DevCronin


Print Share Comment Cite Upload Translate Updates
APA

DevCronin | Sciencx (2021-09-04T17:54:57+00:00) LEVEL UP with JavaScript! LVL 5. Retrieved from https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/

MLA
" » LEVEL UP with JavaScript! LVL 5." DevCronin | Sciencx - Saturday September 4, 2021, https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/
HARVARD
DevCronin | Sciencx Saturday September 4, 2021 » LEVEL UP with JavaScript! LVL 5., viewed ,<https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/>
VANCOUVER
DevCronin | Sciencx - » LEVEL UP with JavaScript! LVL 5. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/
CHICAGO
" » LEVEL UP with JavaScript! LVL 5." DevCronin | Sciencx - Accessed . https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/
IEEE
" » LEVEL UP with JavaScript! LVL 5." DevCronin | Sciencx [Online]. Available: https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/. [Accessed: ]
rf:citation
» LEVEL UP with JavaScript! LVL 5 | DevCronin | Sciencx | https://www.scien.cx/2021/09/04/level-up-with-javascript-lvl-5/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.