In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use 18 JavaScript entry skills, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1. Swivel string
Const input = 123; console.log (input +'); / / '123' console.log (String (input)); / / '123' console.log (input.toString ()); / / '123'
two。 Transfer digits
Const input = '123 console.log; console.log (+ input); / / 123 console.log (Number (input)); / / 123 console.log (parseInt (input)); / / 123
3. Boolean value
Const input = 1; / / scenario 1-use double exclamation point (!!) Convert to a Boolean console.log (!! input); / / true / / scenario 2-use the Boolean () method console.log (Boolean (input)); / / true
4. There is a problem with the string 'false'
Const value = 'false'; console.log (Boolean (value)); / / true console.log (!! value); / / true / / the best way to check console.log (value = =' false')
5.null vs undefined
Null is a value, while undefined is not a value. Null is like an empty box, while undefined has no box.
Const fn = (x = 'default') = > console.log (x); fn (undefined); / / default fn (); / / default fn (null); / / null
If you pass null, the default value is not used, and when you pass undefined or no parameters, the default value is used.
6. True value and imaginary value
Imaginary values: false,0, "", null,undefined and NaN.
Truth: "Values", 0 ", {}, [].
7. Const declares which types of variables can be changed
If the value does not want to be changed, you can use const:
Const name = 'front-end intelligence'; name = 'Wang Daye'; / / error report const list = []; list = [1]; / / error report const obj = {}; obj = {name: 'front-end intelligence'}; / / error report
A reference type that can be declared with const, where the value can be changed:
Const list = []; list.push (1); / / can work list [0] = 2; / / can work const obj = {}; obj ['name'] =' front-end intelligence'; / / can work
8. The difference between third-class sign and double-equal sign
/ / A pair of equal signs-converts two operands to the same type, and then compares console.log (0 = ='o'); / / true / / third class sign-does not convert to the same type console.log (0 = ='0'); / / false
9. A better way to receive parameters
Function downloadData (url, resourceId, searchTest, pageNo, limit) {} downloadData (...); / / need to remember the order
A simpler way
Function downloadData ({url, resourceId, searchTest, pageNo, limit} = {}) {} downloadData ({resourceId: 2, url: "/ posts", searchText: "WebDev"})
10. Change an ordinary function into an arrow function
Const func = function () {console.log ('a'); return 5;}; func ()
Can be rewritten as
Const func = () = > (console.log ('a'), 5); func ()
11. Returns an object / expression from an arrow function
Const getState = (name) = > ({name, message: 'Hi'})
twelve。 Convert set to an array
Const set = new Set ([1,2,1,4,5,6,7,1,2,4]); console.log (set); / / Set (6) {1,2,4,5,6,7} set.map ((num) = > num * num); / / TypeError: set.map is not a function
Convert to an array
Const arr = [... set]
13. Check whether the value is an array
Const arr = [1,2,3]; console.log (typeof arr); / / object console.log (Array.isArray (arr)); / / true
14. Get all the keys of the object
Cosnt obj = {name: "Front-end Intelligence", age: 16, address: "Xiamen", profession: "Front-end Development",}; console.log (Object.keys (obj)); / / name, age, address, profession
15. Double question mark grammar
Const height = 0; console.log (height | | 100); / / 100 console.log (height? 100); / / 0
This? It means, if? The value on the left is null or undefined, so the value on the right is returned.
16. Map ()
The map () method creates a new array, and the result is that each element in the array is the return value after calling the supplied function once.
Const numList = [1,2,3]; const square = (num) = > {return num * num} const squares = numList.map (square); console.log (squares); / / [1,4,9]
17. Try..catch..finally
Const getData = async () = > {try {setLoading (true); const response = await fetch ("https://jsonplaceholder.typicode.com/posts"); const data = await response.json (); setData (data);} catch (error) {console.log (error); setToastMessage (error);} finally {setLoading (false); / / final execution}}, regardless of whether an error is reported or not
18. Deconstruction
Const response = {msg: "success", tags: ["programming", "javascript", "computer"], body: {count: 5},}; const {body: {count, unknownProperty = 'test'},} = response; console.log (count, unknownProperty); / / 5' test'
About 18 JavaScript entry tips on how to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.