Home  >  Article  >  Web Front-end  >  How to define data types in JavaScript

How to define data types in JavaScript

藏色散人
藏色散人Original
2021-07-01 11:42:235196browse

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;".

How to define data types in JavaScript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn