In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about the compound data types of javascript. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
There are three javascript compound data types:
1. Object type, which is an unordered set of keys and values
2. Array type, which is a collection of data arranged in order
3. The Function type is a block of code with specific functions.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Data types in JavaScript can be divided into two types:
Basic data types (value types): string (String), number (Number), Boolean (Boolean), empty (Null), undefined (Undefined), Symbol
Reference data types (compound data types): objects (Object), arrays (Array), functions (Function).
Compound data types of JavaScript
1. Object type
The Object type in JavaScript is an unordered set of keys and values. Curly braces {} are required to define the object type. The syntax format is as follows:
{name1: value1, name2: value2, name3: value3,..., nameN: valueN}
Name1, name2, name3,..., and nameN are the keys in the object, and value1, value2, value3,..., and valueN are the corresponding values.
In JavaScript, the keys of the object type are of string type, and the value can be of any data type. To get a value in an object, you can use the object name. The form of the key, as shown in the following example:
Var person = {name: 'Bob', age: 20, tags: [' js', 'web',' mobile'], city: 'Beijing', hasCar: true, zipcode: null}; console.log (person.name); / / output Bobconsole.log (person.age); / / output 20
2. Array type
An Array is a collection of data arranged in order, each value in the array is called an element, and the array can contain any type of data. Defining an array in JavaScript requires square brackets [], and each element in the array is separated by a comma, for example:
[1,2,3, 'hello', true, null]
Alternatively, you can use the Array () function to create an array, as shown in the following example:
Var arr = new Array (1,2,3,4); console.log (arr); / / output [1,2,3,4]
The elements in the array can be accessed by index. The index in the array starts at 0 and increases in turn, that is, the index of the first element of the array is 0, the index of the second element is 1, the index of the third element is 2, and so on. As shown in the following example:
Var arr = [1,2,3.14, 'Hello', null, true]; console.log (arr [0]); / / output the element with index 0, that is, 1console.log (arr [5]); / / output the element with index 5, that is, trueconsole.log (arr [6]); / / the index is out of range and returns undefined
3. Function type
A function (Function) is a block of code with specific functions. The function does not run automatically, but needs to be called through the function name, as shown in the following example:
Function sayHello (name) {return "Hello," + name;} var res = sayHello ("Peter"); console.log (res); / / output Hello, Peter
In addition, functions can be stored in variables, objects, arrays, and functions can be passed as arguments to or returned from other functions, as shown in the following example:
Var fun = function () {console.log ("http://c.biancheng.net/js/");}function createGreeting (name) {return" Hello, "+ name;} function displayGreeting (greetingFunction, userName) {return greetingFunction (userName);} var result = displayGreeting (createGreeting," Peter "); console.log (result) / / output Hello. What are the compound data types of javascript above Peter? the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.