js data types include: String, Number, Boolean, Null, Undefined, Symbol, Object, Array, Function.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript scripting language, like other languages, has its own basic data types, expressions and arithmetic operators, and the basic program framework of the program.
#What are the data types in js?
JavaScript data type:
Value type (basic type): String, Number, Boolean , for Null, Undefined, and Symbol.
Reference data types: Object, Array, Function.
Note: Symbol is a new primitive data type introduced in ES6 to represent unique values.
JavaScript has dynamic typing:
JavaScript has dynamic typing. This means that the same variable can be used as different types:
Instance
var x; // x 为 undefined var x = 5; // 现在 x 为数字 var x = "John"; // 现在 x 为字符串
JavaScript String
Strings are stored characters (such as " Bill Gates") variable.
The string can be any text in quotes. You can use single or double quotes:
var carname="Volvo XC60"; var carname='Volvo XC60';
You can use quotes within a string as long as they do not match the quotes surrounding the string:
var answer="It's alright"; var answer="He is called 'Johnny'"; var answer='He is called "Johnny"';
JavaScript Numbers
JavaScript has only one number type. Numbers can be written with or without a decimal point:
var x1=34.00; //使用小数点来写 var x2=34; //不使用小数点来写
Very large or very small numbers can be written using scientific (exponential) notation:
var y=123e5; // 12300000 var z=123e-5; // 0.00123
JavaScript Boolean
Boolean (logical) can only have two values: true or false.
var x=true; var y=false;
JavaScript Array
The following code creates an array named cars:
var cars=new Array(); cars[0]="Saab"; cars[1]="Volvo"; cars[2]="BMW";
or
(condensed array): var cars=new Array("Saab","Volvo","BMW");
or
(literal array):
var cars=["Saab","Volvo","BMW"];
Array subscripts are zero-based, so the first item is [0], the second is [1], and so on.
JavaScript Objects
Objects are separated by curly braces. Inside the parentheses, the object's properties are defined in the form of name and value pairs (name : value). Attributes are separated by commas:
var person={firstname:"John", lastname:"Doe", id:5566};
The object (person) in the above example has three attributes: firstname, lastname and id.
Spaces and line breaks don't matter. Declarations can span multiple lines:
var person={ firstname : "John", lastname : "Doe", id : 5566 };
There are two addressing methods for object properties:
name=person.lastname; name=person["lastname"];
Undefined and Null
Undefined This Value means the variable does not contain a value.
You can clear a variable by setting its value to null.
cars=null; person=null;
Declaring 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;
More For related knowledge, please visit the FAQ column!
The above is the detailed content of What are the js data types?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.