In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "an interview question tests the basic skills of JS". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "an interview question to test the basic skills of JS".
/ / get the following results ({} + {}). Length ([] + []) .length (function () {}) .length
This question may confuse you at first glance, and you may wonder: what can you get from the addition of an object and an object? Can you still find out its length?
In fact, this question quite tests the basic skills of a web front-end development engineer.
After seeing this topic, let's first analyze the situation:
1. ({} + {}) .length
The addition of two empty objects is definitely not a numerical operation, so it is only possible that the string is concatenated, then you may get a result like "{} {}", but it is not, because you ignore that the corresponding toString () method is called by default when the string is concatenated.
What does an empty object get when calling the toString () method?
({}) .toString () / "[object Object]"
Get a string like "[object Object]" with a length of 15, then when two empty objects are added together, the length is 30
({} + {}) .length / / is equivalent to ({} .toString () + {} .toString ()) .length / / is "[object Object] [object Object]", and the string length is 30.
2. ([] +]) .length
With the experience of the first question, you might think that if two empty arrays are added together, it must also be a string concatenation, and the toString () method will be called, which is equivalent to finding the length of the string "[object Array] [object Array]", thus getting the final result 28.
However, the toString () method of the array is overridden
] .toString () / / gets a string of elements separated by commas, such as "1Magne2Pol 3".
If an empty array calls the toString () method, all you get is an empty string.
So, the final result of this question is 0.
3. (function () {}) .length
With the experience of the first two topics, you may naturally think that the function here will also call the toString () method. If you think so, you are misled by the first two questions: the length of the function is the number of its formal parameters, so the end result is 0.
Thank you for your reading, the above is the content of "an interview question to test the basic skills of JS". After the study of this article, I believe you have a deeper understanding of the question of testing the basic skills of JS one by one, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.