Table of Contents
Extension operator
Arrow function
Parameter default value, remaining parameters , extended parameters
Home Web Front-end JS Tutorial Some basic explanations of JavaScript

Some basic explanations of JavaScript

Jul 20, 2017 pm 02:36 PM
function parameter operator

The spread operator is represented by three dots. Its function is to expand an array or array-like object into a series of values ​​separated by commas. The spread operator has several functions. Let me explain them one by one! ! !

1, expand the array

//Expand the array let a = [1,2,3,4,5],b = [...a,6,7];console. log(b);//Printed value [1, 2, 3, 4, 5, 6, 7]

2, copy of the array

//Array Copy var c = [1, 2, 3]; var d = [...c]; d.push(4); console.log(d);//Printed value [1, 2, 3, 4 ]

3. Merging of arrays

//Merge of arrays var j = [7, 1, 2]; var k = [5, 0, 8]; j = [...k, ...j];console.log(j)//Printed value [5, 0, 8, 7, 1, 2]

Four, expand function Call

//Expand function call function fn(a,b,c,d){
console.log(a+b+c+d);}var p=[1,9, 3,,6];let result=fn(5,...p);Open function call //The printed value 18

The spread operator (spread) is three dots ( ...), converts an array||array-like||string into a comma-separated sequence. This guy is used to operate on arrays and take out all the things in the array

Extension operator

let zzz=[2,4,6];
console.log(zzz);//[2, 4, 6]
console.log(...zzz);//2 4 6

let a=[1,2,3];
let b=[...a,4,5,6];
console.log(b);//1,2,3,4,5,6

let [a,b,...c]=[1,2,3,4,5];
console.log(a,b);//1 2
console.log(c);//[3, 4, 5]
Copy after login

Arrow function

let say333=()=>{
    console.log("333");//333
}
say333();

(name)=>{
    console.log(name);
}

(a,b)=>{
    return a+b;
}

(a,b)=> a+b;
Copy after login

Parameter default value, remaining parameters , extended parameters

let aa=(name='wwrs')=>{
        console.log(`Hello ${name}`);
    }
    aa();//Hello wwrs
    aa('sss');//Hello sss
    
    
let bb=(a,b,c)=>{
        console.log(a+b+c);//9
    }
    let dd=[2,3,4];
    bb(...dd);
    
    
let he=(a,b,c,d)=>{
    console.log(a+b+c+d);//10
}
he(1,2,3,4)

let he1=(s,j,...shi)=>{
    console.log(shi);//[3, 4]
}
he1(1,2,3,4)
Copy after login

The above is the detailed content of Some basic explanations of JavaScript. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Apr 21, 2024 am 10:21 AM

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

What are the benefits of C++ functions returning reference types? What are the benefits of C++ functions returning reference types? Apr 20, 2024 pm 09:12 PM

The benefits of functions returning reference types in C++ include: Performance improvements: Passing by reference avoids object copying, thus saving memory and time. Direct modification: The caller can directly modify the returned reference object without reassigning it. Code simplicity: Passing by reference simplifies the code and requires no additional assignment operations.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.

vivox200ultra parameters and price details vivox200ultra parameters and price details Jun 28, 2024 pm 01:23 PM

The latest official news of vivox200ultra has exposed the parameters and price details of vivox200ultra. It is reported that vivox200ultra will be equipped with a 10x periscope super telephoto lens, and the price starts at about 6999 yuan. It can be seen that it occupies an absolute advantage in photography performance. The following are the parameters and prices of vivox200ultra Come and see the details. 1. Parameter configuration details of vivox200ultra 1. Vivox200ultra rendering From the vivo X200 Ultra rendering, the front of the phone adopts a borderless full-screen design, and the visual effect of the entire front of the phone can be said to be very invincible. 2. vivox200ultra has Blackhawk frame

See all articles