1. Conditional access attributes ?. is a new feature introduced in ES2020. It is a conditional property access operator. When you access a property value of an See the example: let book = {price:10, edition:10, name:"javascript" } console.log(book.page.num) Direct error reporting:
Because the value of If you are not sure whether a value is console.log(book.page?.num) Output:
2. Introduction to Arrow Functions Arrow function is a shorthand method for defining functions that appeared in example: let square = x=>x**2; console.log(square(3)) Output:
The definition of this function is equivalent to the traditional function: function square(x){ return x**2 } Arrow functions are often used to pass an unnamed function as a parameter to another function. let nums = [1,2,3,4].map(x=>x*2) console.log(nums) Output:
Arrow functions make the code look more concise. If you use the traditional nums = [1,2,3,4].map(function(x){return x*2}) console.log(nums) If an arrow function has multiple parameters, they need to be enclosed in parentheses. const add = (x,y)=>x+y; console.log(add(1,2)) If the body of an arrow function has multiple statements, enclose the body in curly braces and use the return keyword to return the value. const add = (x,y)=>{let tmp=x+y;return tmp}; console.log(add(1,2)) At this time, the function body of the arrow function is exactly the same as the function body format of the ordinary This is the end of this article about JavaScript conditional access to properties and arrow functions. For more relevant JavaScript conditional access to properties and arrow functions, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The best solution for implementing digital plus and minus buttons with pure CSS
>>: Button does not specify type as submit. Clicking the button does not jump to the specified URL.
Recently, I encountered a database with the follo...
Parent File import React, { useState } from '...
Table of contents Preface Summary of audio and vi...
The most important interactive design article in ...
B-Tree Index Different storage engines may also u...
In daily development tasks, we often use MYSQL...
Table of contents 1. New usage of watch 1.1. Watc...
After starting Docker, let's take a look at t...
Table of contents Find and fix table conflicts Up...
Table of contents 1. Add users 2. Change the user...
Examples: Through the PHP background code, you ca...
In this blog, we will discuss ten performance set...
--1. Create a new group and user for mysql # user...
In web design, we often use arrows as decoration ...
Mybatis paging plug-in pageHelper detailed explan...