Seven JavaScript interview questions

Source: Internet
Author: User
Tags hasownproperty

Seven JavaScript interview questions

Last week, I published 7 interview questions for C # programmers. This time I want to talk about how to eliminate JavaScript programmers who are full of resources.

You will be surprised that so many people have come to interview for a job, and their resumes all seem awesome. But if you ask them questions, you will find that they do not know anything about this. I don't know whether these resumes are really just a gimmick. So like other interviewers, I also have a set of methods. First, make sure that the interviewer is worthy of my interview-I can make a phone call within half an hour.

Therefore, if some questions you think should be absent from my 7 questions, it may be because I put them in the next interview session.

In addition, I would like to say to those who may think that the technical interview does not really explain whether the programmer is really good ......

You are right. When I was a young programmer, I felt the same way if I had technical questions. But now I have become an interviewer. I think this method at least proves that people who pass technical interviews are much more likely to be excellent programmers than those who cannot pass technical interviews.

Finally, I would like to say that I will not pass them out because the applicant answered three or two wrong questions or did not answer them as expected. However, if the other party cannot answer most of the questions, I will give him a red light!

The following seven JavaScript interview questions should be asked before the interview. Otherwise, your time may be wasted.

1. What are the two methods for creating JavaScript objects?

This is a very simple problem if you have used JavaScript. You have at least learned one way. However, based on my experience, many people who claim to be JavaScript programmers say they do not know how to answer this question.

  • Use the "new" keyword to call a function.

  • Open/close curly braces.

Var o = {};

You can also ask, "When to create an object using the new keyword ?" However, I only want to eliminate some people, so I will wait for the real interview to ask these questions.

2. How to create an array?

This is the same level as "how to create objects. However, some people cannot answer the first question.

Use the following code to create an array:

Var myArray = new Array ();

Creating arrays is a complicated process. But I want to hear the answer using square brackets from the applicant's mouth.

Var myArray = [];

Of course, we can continue to ask other questions, such as how to efficiently Delete repeated elements in the JavaScript array. However, as we only need to know whether the candidates are worth further observation, I will end the problem of array.

3. What is Variable elevation Variable Hoisting )?

This question is a little difficult, and I do not require the other party to answer it. However, through this question, we can quickly determine the technical level of candidates: Do they really understand the programming language as they declared?

Variable escalation means that no matter where the variable is declared within a range, the JavaScript engine moves the declaration to the top of the range. If a variable is declared in the middle of the function, for example, assigning a variable to a row:

Function foo ()
{
// Some code is omitted here
Var a = "abc ";
}

The code will actually run like this:

Function foo ()
{
Var;
// Some code is omitted here
A = "abc ";
}

4. What are the risks of global variables and how to protect the code from interference?

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

There are also many preventive methods. The most common method is to create a global variable that contains all other variables:

Var applicationName = {};

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

ApplicationName. myVariable = "abc ";

Another way is to encapsulate all the code into an automatically executed 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 to 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 isClosureClosure )?

A closure allows a function to be defined within the scope of another external function. Even if everything in the scope disappears, it can still access the variables in the external function. If the applicant can explain the risks of using closures in the for/next loop without declaring variables to save the current value of the iteration variable, the other party should be given extra points.

7. Describe the JavaScript unit test you have experienced.

For this question, we just want to see if the applicant has actually performed a JavaScript unit test. This is an open question and there is no specific correct answer, but the other party must at least be able to tell something in the process.

You are welcome to add.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.