Share 12 interview questions to see if you understand JavaScript!
Sep 14, 2022 pm 07:36 PMDo you know JavaScript? The following article will share with you 12 JavaScript interview questions. Try these 12 interview questions and see if you can answer them all correctly!
JavaScript is a basic technology that every front-end developer should master, but many times, you may not fully understand JavaScript.
There are two very simple ways to test a person's technical level, look at the code he writes, or let him look at the code written by others.
I have summarized some code questions that can test your understanding of JavaScript. You can try it and see if you can answer them all correctly. If you answer all the questions correctly, you will be considered to know some JavaScript.
First question
Try to guess its output:
1 2 3 4 5 |
|
Output:
1 2 |
|
Analysis:
Many people easily mistake the second output because properties defined using defineProperty are not enumerable by default.
Second Question
Try to guess its output:
1 2 3 4 5 6 |
|
Output:
1 2 3 |
|
Analysis:
The first false is because delete can only delete attributes on the object, and name is not an attribute, so the deletion fails.
The second true is because we do not use any declaration to create the variable. It will be regarded as a global variable and mounted on the window object, which is equivalent to delete window.age, so the deletion is successful.
The third undefined is because age was deleted.
The third question
Try to guess its output:
1 2 3 4 |
|
Output:
1 2 3 |
|
Analysis:
Many people will think that the output result should be [null], but we just set a new reference to the person variable, and the previous reference is still in members.
To put it simply, { name: 'Code and Beast' } This object exists in a certain memory space, assuming its address is X201. Its logic is roughly as follows:
1 2 3 |
|
Question 4
Try to guess Its output:
1 2 3 4 5 6 7 |
|
Output:
1 2 3 |
|
Parsing:
If the constructor finally returns an object, all previously set properties will be invalid.
Question 5
Try to guess its output:
1 2 3 |
|
Output:
1 2 |
|
Analysis:
padStart method can fill spaces at the beginning of the string.
The parameter is the total length of the new string. If this length is shorter than the original string length, it will not be filled.
Question 6
Try to guess its output:
1 2 3 |
|
Output:
1 2 3 |
|
Analysis:
If the parameter of parseInt is a combination of string and number, then it will check from the beginning until it encounters the position with the wrong data type. If there is a valid position before the position with the wrong data type Number, it will return a number.
Question 7
Try to guess its output:
1 |
|
Output:
1 2 3 4 5 6 |
|
Analysis:
If we do not pass the initial value to reduce, then x will be the first value of the array and y will be the second value of the array.
Question 8
Try to guess its output:
1 2 3 4 5 6 7 8 9 10 11 |
|
Output:
1 2 3 4 5 6 |
|
Analysis:
When we use template string syntax to call a function, the first parameter is always a split string array. The remaining parameters are the values of the template expression.
Question 9
Try to guess its output:
1 2 3 4 5 6 7 8 9 10 11 |
|
Output:
1 2 3 |
|
Analysis:
When accessing x in catch, the parameters are accessed, not the external variable x.
Question 10
Try to guess its output:
1 2 3 |
|
Output:
1 |
|
解析:
在 JavaScript 中,Class 也是 function。
第十一题
尝试推测它的输出:
1 2 3 4 |
|
输出:
1 2 3 4 5 |
|
第十二题
尝试推测它的输出:
1 2 3 4 5 |
|
输出:
1 |
|
解析:
with 的对象会作为 global 对象。在 with 使用 var 等价于 window.[xxx]。而这时 foo 就是那个 window。
【相关推荐:javascript学习教程】
The above is the detailed content of Share 12 interview questions to see if you understand JavaScript!. For more information, please follow other related articles on the PHP Chinese website!

Hot tools Tags

Hot Article

Hot tools Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement an online speech recognition system using WebSocket and JavaScript

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript

How to use JavaScript and WebSocket to implement a real-time online ordering system

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Simple JavaScript Tutorial: How to Get HTTP Status Code

How to get HTTP status code in JavaScript the easy way

How to use insertBefore in javascript
