Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JavaScript Array and Boolean example Analysis

2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the JavaScript array and Boolean case analysis related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this JavaScript array and Boolean case analysis article, let's take a look at it.

JavaScript Boolean

Boolean (logical) can only have two values: true or false.

Varx=true

Vary=false

Boolean is often used in conditional testing. You will learn more about conditional testing later in this tutorial.

JavaScript array

The following code creates an array named cars:

Varcars=newArray ()

Cars [0] = "Saab"

Cars [1] = "Volvo"

Cars [2] = "BMW"

Or (condensedarray):

Varcars=newArray ("Saab", "Volvo", "BMW")

Or (literalarray):

Example

Varcars= ["Saab", "Volvo", "BMW"]

The array subscript is based on zero, so the first item is [0], the second is [1], and so on.

You will learn more about arrays later in this tutorial.

JavaScript object

Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Properties are separated by commas:

Varperson= {firstname: "John", lastname: "Doe", id:5566}

The object (person) in the above example has three properties: firstname, lastname, and id.

Spaces and line breaks don't matter. Declarations can span multiple lines:

Var person= {

Firstname: "John"

Lastname: "Doe"

Id: 5566

}

Object properties can be addressed in two ways:

Example

Name=person.lastname

Name=person ["lastname"]

You will learn more about objects later in this tutorial.

Undefined and Null

The value Undefined indicates that the variable does not have a value.

You can empty a variable by setting its value to null.

Example

Cars=null

Person=null

Declare 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

This is the end of the article on "JavaScript Array and Boolean example Analysis". Thank you for reading! I believe you all have a certain understanding of the knowledge of "JavaScript array and Boolean case analysis". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report