Home > Article > Web Front-end > How to define data types in JavaScript
In JavaScript, the declared data type can be defined through the keyword "new", and the definition syntax is such as "var carname=new String;var x= new Number;".
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
How does JavaScript define data types?
JavaScript data types
String value, numeric value, Boolean value, array, object.
JavaScript data types
JavaScript variables can save multiple data types: numerical values, string values, arrays, objects, etc.:
var length = 7; // 数字 var lastName = "Gates"; // 字符串 var cars = ["Porsche", "Volvo", "BMW"]; // 数组 var x = {firstName:"Bill", lastName:"Gates"}; // 对象
Define variable types:
When you declare a new variable, you can use the keyword "new" to declare its type:
var carname=new String; var x= new Number; var y= new Boolean; var cars= new Array; var person= new Object;
Recommended study: "javascript Advanced Tutorial"
The above is the detailed content of How to define data types in JavaScript. For more information, please follow other related articles on the PHP Chinese website!