In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the questions of JavaScript". In daily operation, I believe many people have doubts about the questions of JavaScript. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are the questions of JavaScript?" Next, please follow the editor to study!
Question 1: Fran IIFE _ HOF
Does the following code snippet immediately call function expressions (IIFE), higher-order functions (HOF), or neither?
((fn, val) = > {return fn (val);}) (console.log, 5); answer: output 5 question 2: which of the following array conversion methods is more appropriate? const arr = [1,2,3]; / / the first const a = arr.reduce ((acc, el, I) = > ({... acc, [el]: I}), {}); / / the second const b = {}; for (let I = 0; I)
< arr.length; i++) { b[arr[i]] = i;}答案:第二种 当 b 对象被设置时,b[arr[i]]属性被设置为在每次迭代的当前索引。设置a时,扩展语法(...)将 acc 在每次迭代时创建累加器对象()的浅拷贝,并另外设置新属性。与不执行浅拷贝相比,此浅拷贝更加浪费。a需要在达到结果之前构造2个中间对象,而 b 不会构造任何中间对象。因此,b 被更有效地设置。 问题3 考虑以下函数:superheroMaker的功能。当我们传递以下两个参数时,输出什么? const superheroMaker = a =>{return an instanceof Function? A (): a;}; console.log (superheroMaker (() = > 'Batman')); console.log (superheroMaker (' Superman')); answer: output "Batman"Superman"
When passing () = > 'Batman' to superheroMaker, an is the instance Function of. Therefore, the function is called and the string "Batman" is returned. When "Superman" is passed to superheroMaker, an it is not an instance of, so Function "Superman" only returns a string. Therefore, the output is "Batman" and "Superman".
Is the question 4:Object.keys equal to Object.values? Object Keys, Object Valuesconst obj = {1: 1, 2: 2, 3: 3}; console.log (Object.keys (obj) = = Object.values (obj)); answer: output false
In this case, Object.keys converts the key to a string ["1", "2", "3"], but Object.values returns: [1, 2, 3]. Even if the values are of the same type, they are not the same object, so the equality comparison returns false.
Question 5: basic recursive inspection?
Consider the following recursive functions. If you pass the string "Hello World" to it, what does it output?
Const myFunc = str = > {if (str.length > 1) {return myFunc (str.slice (1));} return str;}; console.log (myFunc ('Hello world')); answer: output "d"
The first time this function is called, str.length it is greater than 1 ("Hello World" means 11 characters), so we return the same function called str.slice (1), that is, string "ello World". We repeat this process until the string is only one character long: the character "d", which is returned to the original call to myFunc. Then we record the character.
Problem 6: function equality
What does the following code output?
Const a = c = > c * Const b = c = > c * console.log (a = = b); console.log (a (7) = b (7)); answer: output false,true
In the first test, an and b are different objects in memory; it doesn't matter if the parameters and return values in each function definition are the same. Therefore, an is not equal to b. In the second test, a (7) returns the number 7 and b (7) returns number 7. These primitive types are strictly equal to each other.
In this case, the equality (= =) and identity (=) comparison operators do not matter; any type of enforcement does not affect the result.
Question 7: object properties are equal
An and b have the same different object firstName properties. Are these attributes strictly equal to each other?
Const a = {firstName: 'Bill'}; const b = {firstName:' Bill'}; console.log (a.firstName = b.firstName); answer: output true
The answer is yes. A.firstName is the string value "Bill" and b.firstName is the string value "Bill". Two identical strings are always equal.
Question 8: functional function syntax
Suppose myFunc is a function, val1 is a variable, and val2 is a variable. Does JavaScript allow the following syntax?
MyFunc (val1) (val2); answer: allow
This is a common pattern of higher-order functions. If myFunc (val1) returns a function, the function is called with val2 as an argument. This is a practical example, and you can try it:
Const timesTable = num1 = > {return num2 = > {return num1 * num2;};}; console.log (timesTable (4) (5)); / / 20 question 9: object attribute mutation const a = {firstName: 'Joe'}; const b = a Joe' b.firstName =' Pete';console.log (a); answer: output {firstName: 'Pete'}
When we set b = an in the second line, b and a point to the same object in memory. So changing the property of firstName,b to on will change the property of the only object in firstName memory, so a.firstName will reflect this change.
Question 10: the maximum number in the array
Will the following function always return the largest number in the array?
Function greatestNumberInArray (arr) {let greatest = 0; for (let I = 0; I < arr.length; iTunes +) {if (greatest < arr [I]) {greatest = arr [I];}} return greatest;} answer: the output is not
If one of the values in the array is greater than 0, it is correct, and if it is all less than 0, it returns 0.
This function is correct for at least one array with a value of 0 greater than or equal to one. However, if all numbers are lower than, it returns 0.
At this point, the study of "what are the JavaScript question and answer questions" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.