Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What interview questions does JavaScript have?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what interview questions JavaScript has". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what interview questions JavaScript has" together!

1. What are the two ways to create JavaScript objects?

It's a very simple question if you've ever used JavaScript. You have to know at least one way. However, despite this, in my experience there are also a lot of self-proclaimed JavaScript programmers who say they don't know how to answer this question.

Use the "new" keyword to call a function.

open/close braces.

var o = {};

You can also ask,"When do you create objects using the new keyword? "But since I'm just trying to weed out some people, these are questions I'll wait until the actual interview.

2. How to create an array?

This is on the same level as "how to create objects." However, there are also some people who can answer *** questions but cannot answer this question.

Using the following code, you can easily create an array:

var myArray = new Array();

Creating arrays is a complex process. But I would like to hear square bracketed answers from candidates.

var myArray = [];

Of course, we could go on to ask other questions, such as how to efficiently remove duplicate elements from JavaScript arrays, but since we only need to know if the candidate deserves further observation, I'll stop with the array questions.

3. What is Variable Hoisting?

This question is a bit more difficult, and I don't expect the other party to answer it. But it's a quick way to determine a candidate's skill level: Do they really understand the programming language as they claim?

Variable promotion means that wherever a variable is declared within a scope, the JavaScript engine will move that declaration to the top of the scope. If you declare a variable in the middle of a function, such as assigning a variable in a line:

function foo()

{

//some codes omitted here

var a = "abc";

}

This actually runs the code:

function foo()

{

var a;

//some codes omitted here

a = "abc";

}

4. What are the risks of global variables, and how can I protect my code from interference?

The danger with global variables is that someone else can create a variable with the same name and then overwrite the variable you are using. This is a headache in any language.

There are many ways to prevent it. The most common method is to create a global variable that contains all the other variables:

var applicationName = {};

Then, whenever you need to create a global variable, just attach it to the object.

applicationName.myVariable = "abc";

Another approach is to wrap all the code in an auto-executing function, so that all declared variables are declared within the scope of the function.

(function(){

var a = "abc";

})();

In reality, you may use both methods.

5. How do I iterate through member variables in JavaScript objects?

for(var prop in obj){

// bonus points for hasOwnProperty

if(obj.hasOwnProperty(prop)){

// do something here

}

}

6. What is Closure?

Closures allow a function to be defined in the scope of another outer function, and it can still access variables within that outer function even if everything else in the scope disappears. If the candidate can explain some of the risks of using closures in a for/next loop without declaring variables to preserve the current value of iteration variables, the candidate should be given credit.

7. Please describe a JavaScript unit test you have experienced.

On this question, we really just want to see if the candidate has actually done JavaScript unit testing. This is an open-ended question, with no specific right answer, but the other person has to be able to tell at least something about the process.

Thank you for reading, the above is the content of "JavaScript has what interview questions", after the study of this article, I believe that everyone has a deeper understanding of JavaScript what interview questions this question, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report