Automatic Type Conversion

By: Dusty Arlia
Published on September 4, 2012
Last Updated on Sunday, July 05, 2015 at 4:40 PM
Total Updates: 4

Automatic type conversion is a task performed by the JavaScript interpreter to change a variable's data type to another data type. It occurs automatically based on the operation being performed and the other objects in the equation. For example:

var totalItemsSelected = 3;
var message = "You have " + totalItemsSelected + " items selected.";

In this example the totalItemsSelected variable gets converted to a string. This is triggered by the string and + operator. Obviously you can't perform addition on a string, so the + operator is used as the concatenation operator and the number 3 gets converted to a string 3.

Comments:

Ad:

Ad: