Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use JavaScript comparison operators and logical operators

Shulou Source: shulou.com Published: 2022-06-01 13:13:39 09月18日 Update

This article mainly shows you "JavaScript comparison operator and logic operator how to use", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "JavaScript comparison operator and logic operator how to use" this article.

JavaScript data type

String, number, Boolean, array, object, Null, Undefined

JavaScript has dynamic types

JavaScript has dynamic types. This means that the same variable can be used as different types:

Var x / / x is undefinedvar x = 6; / / x is a number var x = "Bill"; / / x is a string

JavaScript string

A string is a variable that stores characters, such as "Bill Gates".

The string can be any text in quotation marks. You can use single or double quotation marks:

Var carname= "Bill Gates"; var carname= "Bill Gates"

You can use quotation marks in a string, as long as they do not match the quotation marks that surround the string:

Var answer= "Nice to meet you!"; var answer= "He is called" Bill ""; var answer= "He is called" Bill ""

JavaScript digit

JavaScript has only one numeric type. Numbers can be decimal or not:

Var x1 to 34. 00; / / write var x2 to 34 with decimal point; / / write without decimal point

Very large or very small numbers can be written by scientific (exponential) counting:

Var yearly 123e5; / / 12300000var zonal 123eMur5; / / 0.00123

JavaScript Boolean

Boolean (logical) can only have two values: true or false. Boolean is often used in conditional testing.

Var x=truevar y=false

JavaScript array

The following code creates an array named cars:

Var cars=new Array (); cars [0] = "Audi"; cars [1] = "BMW"; cars [2] = "Volvo"

Or (condensed array):

Var cars=new Array ("Audi", "BMW", "Volvo")

Or (literal array):

Var cars= ["Audi", "BMW", "Volvo"]

Example

Var i; var cars = new Array (); cars [0] = "Audi"; cars [1] = "BMW"; cars [2] = "Volvo"; for

Tags: Variables characters objects strings types operators operations numbers quotes logic attributes Boolean arrays content instances decimals decimal points articles dynamics can be obtained through the Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Microsoft MySQL NVidia