Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Concatenating a String and Another Data Type

To concatinate two or more strings, use + (the concatination operator). To concatinate a string and a number, also use the concatination operator. This is because JavaScript coerces (converts) the number to a string. Shown below is an example:

var amt = 4.35;
var total = "The total is " + amt;

Result: The total is 43.45

Using the + operator with two numbers will add the two numbers and return the sum. Shown below is an example:

var amt1 = 4.35;
var amt2 = 5.65;
var total =  amt1 + amt2;

Result: 10

But using the + operator with a number in a string data type and a number returns a string with an incorrect result. Shown below is an example:

var amt1 = 4.35;
var amt2 = "5.65";
var total =  amt1 + amt2;

Result: 4.355.65

To use the + operator with a number, or numbers, in a string data type requires passing the strings to either parseInt() or parseFloat() to convert the strings to numbers. An example is shown below.

var strNum1 = "43";
var strNum2 = "35";
var total = parseInt(strNum1) + parseInt(strNum2);

Result: 78

More Java Script Code:
• Code for Java Script Cube / Box Volume Calculator
• Concatenating a String and Another Data Type
• Prevent Automated Form Submissions With Java Script
• Easy Java Script Code to Fill Array With Random Numbers
• Using the Java Script Array Object
• JavaScript Cookbook
• How to Disable the Browser Back Button
• Code for Java Script Circle/Sphere Calculator
• Where Did the User Click?
• Submit Forms Without CGI

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268