27 JAVASCRIPT INTERVIEW QUESTIONS AND ANSWERS FOR 2019 - PREPARED BY DEVTEAM.SPACE

Page created by Earl Dixon
 
CONTINUE READING
27 JAVASCRIPT INTERVIEW QUESTIONS AND ANSWERS FOR 2019 - PREPARED BY DEVTEAM.SPACE
27 JavaScript Interview
Questions and Answers for 2019
         Prepared by DevTeam.Space
27 JAVASCRIPT INTERVIEW QUESTIONS AND ANSWERS FOR 2019 - PREPARED BY DEVTEAM.SPACE
DevTeam.Space is a data-driven agile
              software development platform

    Successful businesses and entrepreneurs
        rely on DevTeam.Space for their most
                         innovative projects

●   mail@devteam.space         ●    415-570-7043                         ●   https://devteam.space

                         © DevTeam.Space. Confidential and proprietary
Whether you’re an entrepreneur, a project manager in a large enterprise, or a CTO, you are well
aware that the success of your JavaScript project rests on your ability to find top developers.

In this guide, you’ll find example interview questions and answers you can refer to when seeking a
new JavaScript developer to make your dynamic user interfaces come to life. You’ll also get some
practical advice on how to use these questions to reliably identify the best people for the job.

First Things First: Select Your Job Requirements
The biggest mistake you can make as an interviewer is not knowing exactly what kind of JavaScript
developer you are looking before you sit down with your candidates. And no, “a great JavaScript
developer with lots of experience” is not specific enough.

You need to be able to reliably identify the right candidates capable of completing the
JavaScript-specific tasks for your project with your team. To do that, you need to figure out your
specific job requirements.

Some example requirements for a JavaScript developer include:

   ●   Essential web development skills ​– HTML, CSS
   ●   JavaScript-specific skills ​– Libraries and toolkits, testing code
   ●   Design skills​ – Building scalable applications, security
   ●   Communication skills​ – Discussing problems and constraints
   ●   Initiative​ – Figuring out solutions by themselves

Avoid making a laundry list of non-essential skills for your perfect JavaScript developer. Instead,
focus on what your candidate will actually be doing day-to-day. Keep your requirements list as short
as possible. Cut anything they can do without or learn on the job.

   ●   mail@devteam.space              ●    415-570-7043                         ●   https://devteam.space

                                 © DevTeam.Space. Confidential and proprietary
With clearly stated requirements, you’ll be able to choose the right JavaScript coding interview
questions and have a much better idea of what kinds of responses you are looking for.

The questions in this guide are broken down into two sections: Basic Interview Questions and
Advanced Interview Questions. You should use the basic JavaScript programming interview
questions in this section if you’re looking for a junior or entry level developer with less
experience.

Skip to the ​Advanced​ developer sections for ​JavaScript​ interview questions and answers for
experienced developers).​

JavaScript Basic Interview Questions
A Junior developer is someone just starting their career with less than 2 years of experience. They
demand the lowest salary, but they’ll need guidance from more experienced JavaScript developers
who can delegate tasks and cross-check their code.

Skill Requirements for Junior JavaScript Developers

    ●   Essential web technologies (HTML, CSS)
    ●   Foundational JavaScript knowledge
    ●   Learning on the job
    ●   Following instructions and receiving feedback
    ●   Thinking like a programmer

Example Java Basic Interview Questions and Answers
Note: Important keywords are underlined in the answers. Bonus points if the candidate mentions
them!

Question 1: ​What is JavaScript?
Requirement: Foundational JavaScript Knowledge

Answer:​ ​JavaScript is a high-level, ​object-based​, ​dynamically typed​, ​weakly typed​, ​interpreted​,
multi-paradigm programming language. It is one of the three core web technologies alongside
HTML and CSS. It was originally a client-side scripting language but can also be used server-side.

Question 2: ​What are the JavaScript Data Types?
Requirement: Foundational JavaScript Knowledge

Answer:​ J​avaScript is a high-level, ​object-based​, ​dynamically typed​, ​weakly typed​, ​interpreted​,

    ●   mail@devteam.space               ●    415-570-7043                         ●   https://devteam.space

                                   © DevTeam.Space. Confidential and proprietary
multi-paradigm programming language. It is one of the three core web technologies alongside
HTML and CSS. It was
originally a client-side scripting language but can also be used server-side.

Question 3: ​Describe the difference between undeclared and undefined variables.
Requirement: Foundational JavaScript Knowledge

Answer:​ ​Undeclared variables have not been declared in the scope of the program and don’t exist.
If a JavaScript program tries to read an undeclared variable, a ​runtime error​ will occur.

Undefined variables have been declared but haven’t been ​assigned a value​. If a JavaScript program
tries to read an undefined variable there won’t be an error, but an undefined value will be returned.

Question 4: ​Write some example JavaScript code that creates a new HTML  element with
some text, and appends it to the document body. Use jQuery syntax if needed.
Requirement: Foundational JavaScript Knowledge

Answer:

var para = document.createElement("P");​ ​// Create a  element
    ​var t = document.createTextNode("This is a paragraph");​ ​// Create a text
node
    ​para.appendChild(t);​ ​// Append the text to 
    ​document.body.appendChild(para);​ ​// Append  to 

Question 5: ​Write an example definition of a JavaScript object for a ‘person’. The object should
have a first and last name, an id number, and a function to retrieve the full name of the person.
Requirement: Foundational JavaScript Knowledge

Answer: ​Here you’re looking for basic knowledge of how to turn spoken requirements into working
JavaScript code. Look out for things like naming conventions, neat code structure, correct use of
keywords, correct semicolon use, and syntax errors. A acceptable answer should look something
like this:

var person = {
             ​firstName : "John",
             ​lastName : "Doe",

   ●   mail@devteam.space             ●    415-570-7043                         ●   https://devteam.space

                                © DevTeam.Space. Confidential and proprietary
​id   ​ ​     : 0001,
                fullName : function() {
                            ​return this.firstName + " " + this.lastName;
                }
       }

Question 6: ​Describe what ‘dynamic typing’ means for JavaScript. Give code examples.
Requirement: Foundational JavaScript Knowledge

Answer:​ ​Dynamic typing means that the ​type​ of variables can ​change at runtime​. For example, this is
perfectly ok in JavaScript:
   ​n = 1;
     ​n = “Some string”;

This is opposed to static typing, where the programmer must explicitly state the type of each
variable and conversions to unrelated types must be done explicitly.

Question 7: ​Write an example of a simple HTML document with some header information and
some page content.
Requirement: Basic HTML skills

Answer: ​HTML documents are different, but they follow a basic structure of head and body. The
different sections are marked with ​tags​ such as DOCTYPE, html, head, title, meta, body, h1, p.
For example:

           ​
              ​Page Title
              ​
              
           ​
            
              Interview Example Web Page
              Some content goes here
            
   ●       mail@devteam.space             ●    415-570-7043                         ●   https://devteam.space

                                    © DevTeam.Space. Confidential and proprietary
Question 8: ​Explain JavaScript callback functions and provide a simple example.
Requirement: Basic JavaScript skills

Answer:​ ​A callback function is a function that is ​called after another function has finished​ executing.
A callback function is passed to another function as an ​argument​ and is invoked after some
operation has been completed. For example:
    ​       function modifyArray(arr, callback) {
                  arr.push(100);
                 ​callback();
            ​}

            ​var arr = [1, 2, 3, 4, 5];
            modifyArray(arr, function() {
                 ​console.log("array has been modified", arr);
            });

Question 9: ​How would you learn about a new JavaScript library?
Requirement: Learning on the job

Answer:​ ​Web development is changing all the time, and developers need to be able to learn
constantly. Here you are finding out how the candidate approaches the learning process. You want
to see that they have an idea of what information they will need and where to find it. For JavaScript
libraries, that means looking up online tutorials and digging into the documentation.

Question 10: ​Describe a time you received feedback on a programming task. How did it help you
become a better programmer?
Requirement: Following instructions and receiving feedback

Answer:​ ​This is a typical open-ended question. The candidate should demonstrate they can accept,
understand and act on feedback.

               ​ hat will be the output when the following code is executed? Explain.
Question 11: ​ W
            console.log(false == '0')
            console.log(false === '0')

        ●        mail@devteam.space         ●    415-570-7043                         ●   https://devteam.space

                                      © DevTeam.Space. Confidential and proprietary
Answer:
true

false

Explanation:​ == equal to, === equal to with datatype check

JavaScript Advanced Interview Questions

Here are some more advanced and technical interview questions and answers for experienced
JavaScript developers. Use them to pick out the right JavaScript developers with the skills to build
your web app.

Modern web development is all about understanding how to use tools, libraries and toolkits and
integrate many technologies together. Expert developers need to know more than just how to write
excellent JavaScript code. They need to know how that code will work in the context of the
application and the entire web.

For this reason, you should include a lot of open-ended, ‘messy’ interview questions. These should
spark a discussion and you should tailor them to fit your own job requirements. Don’t be afraid to
ask follow-up questions!

Skill Requirements for Mid-Level Java Developers

   ●    Expert JavaScript knowledge
   ●    Using a range of web technologies
   ●    Designing for specific requirements (e.g. security, scalability)
   ●    Node.js and server-side JavaScript
   ●    Maintaining and upgrading JavaScript applications
   ●    Experience in frameworks/toolkits/libraries you use
   ●    Efficient programming and clean code
   ● D​ebugging
   ●    Automated testing
   ●    Leadership skills
   ●    Clear communication skills
   ●    Mentoring less experienced developers

   ●    mail@devteam.space              ●    415-570-7043                         ●   https://devteam.space

                                  © DevTeam.Space. Confidential and proprietary
Example JavaScript Interview Questions and Answers
Note: Important keywords are ​underlined​ in the answers. Look out for them in interviews!

Question 12: ​List some advantages and disadvantages of JavaScript?
Requirement: Expert JavaScript knowledge

With this question, you’re looking for knowledge of how programming languages work, and why
there are always ​tradeoffs​ to any specific web technology or language.

Answer:
Advantages:

   ●   Being able to compile and run immediately within the browser makes it fast in many cases
   ●   It’s interoperable with many other languages and can be inserted into any webpage
   ●   A huge number of tools, libraries and frameworks are available
   ●   Most programmers know at least some JavaScript and extensive resources available to learn
       JavaScript
   ●   It’s a highly versatile language
   ●   You can use JavaScript as a server-side language with Node.js
   ●   Allows web pages to have interactive elements and interfaces

Disadvantages:

   ●   JavaScript has some security vulnerabilities. Code compiled and run on the client-side can
       be exploited by attackers
   ●   Features like dynamic typing can make JavaScript code prone to errors
   ●   JavaScript may run differently on different browsers

Question 13: ​What will be the output of the following code?
Requirement: Expert JavaScript knowledge
var foo = true;
         ​console.log(!foo);
         ​console.log(foo + 0);
         ​console.log(foo + "xyz");
         ​console.log(foo + false);
         ​console.log(foo && foo);

   ●   mail@devteam.space             ●    415-570-7043                         ●   https://devteam.space

                                © DevTeam.Space. Confidential and proprietary
Answer:
Here you’re looking for knowledge of how variable typing and the logical operators work in
JavaScript. It will output the following to the console:

 ​true
           ​1
           ​truexyz
           ​1
           ​true

Question 14: ​What will the following code output? Why?
Requirement: Expert JavaScript knowledge

function foo(){
                function bar() {
                    return ‘a’;
                }
                return bar();
                function bar() {
                    return ‘b’;
                }
           }
           console.log(foo());

Answer:
Here you’re testing detailed knowledge of a critical JavaScript concept called ​Hoisting​.

Counterintuitively, the program will output ​b​. This is because both of the bar() functions in the code
snippet will be ​hoisted​ to the top of the scope. The second one returning the string ‘b’ will be
hoisted after the first, so that function will be called in the return statement.

Question 15. ​What is ‘this’ keyword in JavaScript? How do you use it?
Requirement: Expert JavaScript knowledge

Answer:​ ​The ‘this’ keyword refers to the object from where it was called. In their answer, the
candidate should tell about call, bind, and apply.

The functions .call() and .apply() are very similar in their usage, except for one small difference. .call()
is used when the number of the function’s arguments are known to the programmer, as they have to

    ●    mail@devteam.space             ●    415-570-7043                         ●   https://devteam.space

                                  © DevTeam.Space. Confidential and proprietary
be mentioned as arguments in the call statement. On the other hand, .apply() is used when the
number is not known. The function .apply() expects the argument to be an array.

.bind returns a new function(does not invoke it immediately) with the new context

Question 16: ​How do you explain closures in JavaScript? When are they used?
Requirement: Expert JavaScript knowledge

Answer:​ ​A closure is a locally declared variable related to a function which stays in memory when
the function has returned. ​Take a look here for a deeper understanding

For example:

              function greet(message) {
                    console.log(message);
               ​}

               function greeter(name, age) {
                    return name + " says howdy!! He is " + age + " years old";
               ​}

               // Generate the message
               var message = greeter("James", 23);
               // Pass it explicitly to greet
               greet(message);

       ​           This function can be better represented by using closures
               function greeter(name, age) {
               ​ var message = name + " says howdy!! He is " + age + " years old";
               ​ return function greet() {
               ​      console.log(message);
               ​ };
               ​}
               // Generate the closure
               var JamesGreeter = greeter("James", 23);
               // Use the closure

   ●       mail@devteam.space            ●    415-570-7043                         ●   https://devteam.space

                                   © DevTeam.Space. Confidential and proprietary
JamesGreeter();

Question 17: ​How do you copy an object by reference? How do you copy one by value?
Requirement: Expert JavaScript knowledge

Answer:
       ​a = {'w': 1}
       ​b = a ​ ​// copies reference to an object
       ​c = Object.assign({},a) // creates new object which copies the value of A

Question 18: ​Why is namespacing important when coding in JavaScript? Give an example of how
you would implement namespacing to group this sample configuration data:
Requirement: Namespacing

 ​ ​var DEBUG = true;
              ​var MAX_SIZE = 100;
              ​var FEED_URL =​ ​"http://myfeed.com/feed/"​;
              ​var POST_IDS = [1, 2, 3];

Answer: ​Namespacing is used to ​group things like variables, functions and objects​ together with
unique names. It helps to avoid naming conflicts, logically separate code and make code more
reusable.

Namespacing in JavaScript is often done using ​objects​. For the example above:

var Config = {
                    ​DEBUG: true,
                    ​MAX_SIZE: 100,
                    ​FEED_URL:​ "
                                ​ http://myfeed.com/feed/",
                                                          ​
                       POST_IDS: [123, 456, 789]
            };

A variable in this namespace can be accessed like so:

 ​Config.MAX_SIZE;

   ●    mail@devteam.space            ●    415-570-7043                         ●   https://devteam.space

                                © DevTeam.Space. Confidential and proprietary
Question 19: ​Give some ideas to implement automated testing on our JavaScript code?
Requirement: Testing JavaScript applications

Answer: ​Automated testing is essential when building robust applications. Great developers are
keenly familiar with and can implement:

   ●   Unit testing​ – Testing individual functions and classes
   ●   Integration testing​ – Testing that components work together as expected
   ●   UI/Functional testing​ – Testing the interface and functioning of the actual application

Some examples of JavaScript testing tools include Jest, Mocha, Jasmine, Karma, Cucumber, Chai,
Unexpected, enzyme, Ava, Protractor, Casper, Phantom, and many more.

Question 20: ​What are your favorite JavaScript frameworks and technology stacks? Why?
Requirement: Using a range of web technologies

Answer: ​Effective web development requires using and combining the many different technologies
available. Here you’re getting an idea of your candidates depth and breadth of experience in these
tools. You should probe for specific technical details about the answers.

Question 21: ​What architectures and design patterns have you used for building JavaScript
applications? What were the tradeoffs?
Requirement: Web application design

Answer: ​This question is about architecture and design patterns and is distinct from the question
above. It’s for senior candidates that will be part of the design process for your application. Ideally, a
candidate will have experience working with multiple software architectures and understand the
tradeoffs of each.

Some examples they might talk about include model-view-controller pattern, flux architecture,
n-layered, microkernel architecture, microservices, monolithic, client-server, peer-to-peer,
master-slave pattern, pipe-filter pattern, broker pattern, event-bus pattern, interpreter pattern,

Question 22: ​What’s your experience with using server-side JavaScript?
Requirement: Node.js and server-side JavaScript

Answer: ​You’ll need to ask this if your job requires server-side JavaScript using Node.js. Server-side
JavaScript requires different skills to client-side.

   ●   mail@devteam.space               ●    415-570-7043                         ●   https://devteam.space

                                  © DevTeam.Space. Confidential and proprietary
Question 23: ​If you could use whatever tools you like to build our ______ application, what
would you use?
Requirement: Design skills, understanding requirements

Answer: ​You’ll need to ask this if your job requires server-side JavaScript using Node.js. Server-side
JavaScript requires different skills to client-side.

Question 24: ​How are you involved in the JavaScript/Web development community?
Requirement: Passion for web development

Answer: ​ This is a very popular question for coding interviews because community and open source
involvement are clear indicators of a passionate developer.

Question 25: ​Describe a time you fixed a particularly difficult error in a web application. How did
you approach the problem? What debugging tools did you use? What did you learn from this
experience?
Requirement: Debugging, Breaking down a problem into parts

Debugging is one of the key skills for any web developer. However, the real skill is in breaking the
problem down in a practical way rather than finding small errors in code snippets. Debugging often
takes hours or even days, so you don’t have time in an interview setting. Asking these questions will
give you an idea of how your candidate approaches errors and bugs.

Answer: ​ In the candidate’s response you should look out for things like:

   ●   A measured, scientific approach
   ●   Breaking down the problem into parts
   ●   Finding out how to ​reproduce​ the error
   ●   Expressing and then testing ​assumptions
   ●   Looking at ​stack traces
   ●   Getting ​someone else​ to help/take a look
   ●   Searching the internet for others that have had the same problem
   ●   Writing ​tests​ to check if the bug returns
   ●   Checking the rest of the code for similar errors
   ●   Turn problems into learning experiences

Question 26: ​What’s the most important thing to look for or check when reviewing another team
member’s code?
Requirement: Mentoring less experienced developers, Leadership skills

Answer: ​ Here you’re checking for analysis skills, knowledge of mistakes that less experienced

   ●   mail@devteam.space              ●    415-570-7043                         ●   https://devteam.space

                                 © DevTeam.Space. Confidential and proprietary
developers make, keeping in mind the larger project and attention to detail.

A good answer might mention code ​functionality​, ​readability​ and ​style conventions​, ​security flaws
that could lead to system vulnerabilities, simplicity, regulatory requirements, or resource
optimization.

Question 27: What tools & practices do you consider necessary for Continuous Integration
and Delivery for a web application?
Requirement: DevOps systems design, Maintaining and upgrading applications

Summary
Hiring the right people for your development team is critical to the success of your project.
Remember that you should not be aiming to hire the perfect JavaScript developer, but rather the
right person for the job at hand.

With the help of this information and sample interview questions on JavaScript, you can ensure that
the hiring process goes smoothly and successfully – allowing you to hire a great programming team
to get your project completed on time and on budget.

Finally, you can simply print out this ready-to-use cheat sheet of questions and answers and bring
with you to interview your candidates.

Happy Hiring!

    ●   mail@devteam.space              ●    415-570-7043                         ●   https://devteam.space

                                  © DevTeam.Space. Confidential and proprietary
Hear From DevTeam.Space Clients
 DevTeam.Space team is proactive, drawing on operating experience to understand not only your
 vision but also its purpose; they are skilled, making the right judgment calls and iterating quickly;
  and they get customer service, providing honest counsel on cost-benefit and real-time process
       transparency. I highly recommend DTS and look forward to working with them again!
                               Investment Fund / Website development
                                    NIC POULOS​ ​– Bowery Capital

DevTeam.Space has been a great support to us. We needed help with frontend specific projects for
 a big release. They came on board, with almost no time taken in ramping up with our code base
       and were able to deliver on time! For fast, effective service, contact DevTeam.Space.
                                     Consumer Services / Frontend
                                     RAHUL THATHOO​ – MyTime

We had 5 projects and 3 different development teams across multiple tech stacks. One​ ​dashboard
to navigate all the projects, two project managers, daily updates directly from developers, blockers
 tracking, and daily stand-up calls have created a productive atmosphere and helped us to move
    much quicker. If you are looking for high-end software outsourcing services - look no further.
                         Property management / Backend Infrastructure / Data
                                       JASON JOU​ – SenStay

Working with DevTeam.Space was a positive and professional experience from the start. They had
  all the tools in place to support Agile Scrum project management, communicated daily via the
dashboard, delivered their Sprints on time, and stayed on top of project blockers. I look forward to
                                      working with them again!
                                     Fintech / Backend / Frontend
                                    TONY AMOS​ - Principis Capital

          Successful Businesses and Entrepreneurs
                  Rely on DevTeam.Space
             for Their Most Innovative Projects

                                        GET STARTED >

             Tell us about your challenge & get a free strategy session

   ●   mail@devteam.space             ●    415-570-7043                         ●   https://devteam.space

                                © DevTeam.Space. Confidential and proprietary
You can also read