Home > Web Front-end > JS Tutorial > body text

How to define data types in JavaScript

藏色散人
Release: 2023-01-07 11:41:34
Original
5202 people have browsed it

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"};    // 对象
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template