Concatenate Variables Containing Numbers

Concatenate Variables Containing Numbers

I need to know how to concatenate variables containing numbers, that is, string them together one after the other. Every method I know simply adds the various numbers together and spits out the sum.


You’re right?if you simply try to add the variables together using the plus (+) operator you’ll get the values added numerically. For example, given that:

var a = 5;var b = 10;var c = 999;

This code correctly displays the value 1014:

alert (a + b + c);

What you want to do is to trick the JavaScript interpreter into thinking that you want a string result, not a numeric one. An easy way to do that is to include a string constant as one of the items being added. This results in the variables being treated as strings instead of numerals. In addition, if the string you throw into the mix is an empty one it won’t disrupt what you’re trying to accomplish. For example, this code displays 510999 as you’d expect:

alert ("" + a + b + c);

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved