5 typical JavaScript interview questions and javascript interview questions

Source: Internet
Author: User

5 typical JavaScript interview questions and javascript interview questions


Companies in the IT industry still have high requirements for JavaScript developers. However, if the skills and experience of JavaScript developers reach a certain level, they can easily jump to excellent companies, of course, the salary is not a problem. However, the interview preparation should be sufficient before the interview. After all, not every good developer can express himself in a short time. In this article, I will list five common front-end development questions. Here you prove that you must be a programmer or HR. If you want to finish reading the article, check out your shortcomings and ask questions.

Question 1: Scope

Check out the following code:

    (function(){    var a = b =5;    })();    console.log(b);

What will the result be output?

Answer:

5

The main points of this question are two different scopes. 'A' is declared as a local variable by var, but 'B' is not actually defined, so it is a global variable.

Another important issue is strict mode. If you select strict mode, the code above will report Uncaught ReferenceError because B is not defined, it can help you check out some code problems:

    (function(){    'use strict';    var a = window.b =5;    })();    console.log(b);
Question 2: create a "native" method

Write a method for repeatedly printing string objects. Enter an integer that represents the number of words that are repeatedly printed, for example:

  1. Console. log ('hello'. repeatify (3 ));
This will print hellohellohello. Answer:

One of the implementation methods is as follows:

    String.prototype.repeatify =String.prototype.repeatify ||function(times){    var str ='';    for(var i =0; i < times; i++){    str +=this;    }    return str;    };

This question examines how much developers know about JavaScript inheritance and prototype attributes.

Question 3: Hoisting

What is the output result 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 code:

    function test(){    var a;    function foo(){    return2;    }    console.log(a);    console.log(foo());    a =1;    }    test();
Question 4: how to execute

The following code provides the result and explains 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 preceding problem, let the last console. log () Output Aurelio De Rosa.

Answer:

The problem lies in call () or apply (). If you do not know the differences between them, I will build you to read first What's the difference between function. call and function. apply? The following code uses call (), but in this case, apply () produces the same result:

console.log(test.call(obj.prop));

Original article: 5 typical JavaScript interview questions


What are common javascript interview questions?

Variables, syntaxes, and other basic things.
Then, advanced Write Functions with certain functions, such:
Sorting, conversion of strings to arrays, conversion of arrays to strings, and so on
The core of DOM (including HTML, XML, and so on) operations on JavaScript is to operate on elements. This will inevitably be an exam. Otherwise, we should learn how to use JavaScript and remember some common method attributes.
Regular Expressions. Pay attention to a greedy and lazy matching expression.
JS object
Ajax may also have
In addition, CSS will also
There should be some basic things. As long as you have strong basic knowledge, the interview is not a problem.

What are common javascript interview questions?

Variables, syntaxes, and other basic things.
Then, advanced Write Functions with certain functions, such:
Sorting, conversion of strings to arrays, conversion of arrays to strings, and so on
The core of DOM (including HTML, XML, and so on) operations on JavaScript is to operate on elements. This will inevitably be an exam. Otherwise, we should learn how to use JavaScript and remember some common method attributes.
Regular Expressions. Pay attention to a greedy and lazy matching expression.
JS object
Ajax may also have
In addition, CSS will also
There should be some basic things. As long as you have strong basic knowledge, the interview is not a problem.

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.