String Manipulation
Learn about string manipulation with examples.
We'll cover the following...
Calculations with numbers and strings
Is it possible to add a number and string together? It seems a ridiculous question, but JavaScript will try its best to answer the question, as can be seen in the example below:
Press + to interact
console.log(2 + 'two');
What has happened here? The number 2
has been turned into the string
'2'
, and this has been concatenated with the string 'two'
like we saw earlier. This process is called type coercion, and it occurs when the operands of an operator are of different types. JavaScript will attempt to convert one of the operands to an equivalent value of the other operand’s type. For example, if we try to multiply a string and a number together, ...