The requirements for JavaScript developers in the IT community are still high, but if JavaScript developers have the skills and experience to reach a certain level, they can easily jump to a good company, and of course the salary is not a problem. But before the interview, the interview preparation should be sufficient enough, after all, not every good developer can express themselves in a short period of time. In this article, I'll list 5 common front-end development questions. See here you prove that you must be a programmer or HR, not to read the article, to understand what the shortcomings of their own, what the problem I hope you can communicate in the message.
Issue 1: Scope
Take a look at the following code:
(function() { var a = b =5; }) (); Console.log (b);
What does the result output?
Answer:
5
The point of this question is that two different scopes, ' a ' is declared by Var as a local variable, but ' B ' is not actually defined, so it is a global variable.
This problem is also related to another important issue, that is strict mode, if you choose Strict mode, the above code will be reported uncaught Referenceerror, because B is not defined, it can help you check out some of the code problems:
(function() { ' use strict '; var a = window.b =5; }) (); Console.log (b);
Issue 2: Create a "native" method
Write a method that repeats the string object, and enter an integer that represents the number of repeated printed words, such as:
- Console. Log(' hello '). Repeatify(3));
This will print out the Hellohellohello. Answer:
One way to do this is to:
String.prototype.repeatify =string.prototype.repeatify | | function (times) { var str = ' ; for (var i =0; i < times; i++) { += this; } return str; };
This question examines how well developers understand JavaScript inheritance and prototype attributes.
Question 3:hoisting
What is the output of the following code?
function Test () { console.log (a); Console.log (foo ()); var a =1; function foo () { return2; } } Test ();
Answer
Undefined and 2.
The above code is equivalent to the following paragraph:
function Test () { var A; function foo () { return2; } Console.log (a); Console.log (foo ()); =1; } Test ();
Question 4: How to perform in JavaScript
Give the results in the following code to explain your answer:
var fullname = ' John Doe '; var obj ={ fullname:' Colin ihrig ', prop:{ fullname:' Aurelio De Rosa ', Getfullname: function () { returnthis.fullname;}} ; Console.log (Obj.prop.getFullname ()); var test = obj.prop.getFullname; Console.log (Test ());
Answer:
Aurelio De Rosa and John Doe.
Question 5:call () and apply ()
After solving the previous problem let the last Console.log () output Aurelio De Rosa.
Answer:
The question is whether call () or apply (). If you don't know the difference between them, I'll build you first read what ' s the difference between Function.call and function.apply? The following line of code I use Call (), but in this case apply () will also produce the same result:
Console.log (Test.call (Obj.prop));
Original from: 5 classic JavaScript face questions
5 Classic JavaScript face questions