How to Clean up String Concatenation in Programming


show more JavaScript variables can hold numbers or strings, which can make it difficult for beginner programmers to grasp. In this tutorial, Simon teaches how to clean up with string concatenation, and how to use and understand the built-in functions of JavaScript to ensure the variables in your code are correctly recognized. show less
please wait ...

Cleaning up with string concatenation

So JavaScript is a weakly typed language. Meaning our variables can hold numbers, they can hold strings, they can hold Booleans, but JavaScript still cares, it knows the difference, and it treats those values differently. Let me show you an example. If I create two variables, foo and bar, and I give them numeric values, the number 5 without double quotes, then I call alert adding them together. I'm using the addition operator, the plus sign. What I'll get will be the number 10.

It understands these are numbers. It adds them together. If on the other hand, I create these variables with the digit 5, but inside double quotes as a string and then I use exactly the same code, I'm using the addition operator to add them together, what's going to happen is concatenation, not addition. They are going to put them beside each other and what will be output is 55. This is a behavior you do occasionally want to have happen even when the values in your strings are what we think of as numeri...

Cleaning up with string concatenation
Video duration: 4m 30s 4h 47m Beginner

Viewers:

JavaScript variables can hold numbers or strings, which can make it difficult for beginner programmers to grasp. In this tutorial, Simon teaches how to clean up with string concatenation, and how to use and understand the built-in functions of JavaScript to ensure the variables in your code are correctly recognized.

Subjects:
Developer Web
Author:
please wait ...