All Javascript Q&A You Should Know Before An Interview

Published on 12 Feb 2019 . 1 min read



javascript interview questions and answers javascript interview questions and answers

Whether you are a novice in the software industry or an experienced professional, knowing about computer programming languages always helps you immensely.

One such powerful and flexible programming language of the web which powers the dynamic behaviour on most websites is called Javascript.

Often abbreviated as JS, Javascript is a high-level, interpreted programming language that is an essential part of web applications. Along with HTML and CSS, JavaScript is one of the three core technologies of the World Wide Web.

With multiple usages and applications of JS, it has been the most desired skill set in the industry lately. And thus, many interviewers seek for candidates who are well versed with Javascript.

This is why we have thought to come up with some hot favourite interview questions on Javascript. The questions range from a basic to a mid-senior experience level.

Don't miss out this one , When Facing Interview: 11 Best Tips to get job (with DOs & Don'Ts)

Moreover, the questions below are collected from several websites as well as from personal interview experiences.

Experience level : 0 to 3 years

#1. What is JavaScript?

  • JavaScript is a client-side as well as a server-side scripting language.
  • It can be inserted into HTML pages and is understood by web browsers. -JavaScript is also an Object-based Programming language

#2. Enumerate the differences between Java and JavaScript?

Java, on one hand, is a complete programming language whereas, JavaScript is a coded program that can be introduced to HTML pages.

These two languages are not interdependent and are designed for different intent. Also,  Java is an object-oriented programming (OOPS) or structured programming languages like C++ or C and JavaScript is a client-side scripting language.

#3. What are JavaScript Data Types? Are Attributes and Property the same?

The JavaScript Data types are as follows:

  • Number
  • String
  • Boolean
  • Object
  • Undefined

The answer to the second question is No.

Attributes, on one hand, are something that can give more details on an element like id, type, value etc, and on the other hand property is the value assigned to the property like type="text", value='Name' etc.

#4. What is an ECMAScript?

ECMAScript stands for European Computer Manufacturers AssociationScript.

It is a specification for the scripting language standards.

It has standardized Javascript which made Javascript the best implementation of ECMAScript.

#5. List some features of JavaScript.

Some of the features of JavaScript are:

  • Lightweight
  • Interpreted programming language
  • Good for the applications which are network-centric
  • Complementary to Java
  • Complementary to HTML
  • Open source
  • Cross-platform

#6. Name the types of functions and define them

The types of function are:

  • Named - These type of functions contains name at the time of definition.

For Example:

function display()  

{  

 document.writeln("Named Function");  

}  

display();  

  • Anonymous - These type of functions doesn't contain any name. They are declared dynamically at runtime.

For Example:

var display=function()  

{  

 document.writeln("Anonymous Function");  

}  

display();  

#7. In how many ways a Javascript code can be involved in an HTML file?

The Javascript code can be involved in 3 ways

(i) Inline

(ii) Internal

(iii) External

#8. What are the new ways to define a variable in Javascript?

There are three possible ways of defining a variable in Javascript

(i) var (which is used from the beginning)

(ii) const

(iii) let.

The last two ways are the latest ways of defining a variable and are introduced in the ES-2015(ES6 version).

#9. What is the difference between JavaScript and JScript?

You can say JScript is the same as JavaScript, but Microsoft provides it as Netscape provided the JavaScript language but Microsoft changed the name and called it JScript to avoid the trademark issue.

#10. How to write a hello world example of JavaScript?

A simple example of JavaScript hello world is given below.

You have to place it inside the body tag of HTML.

<script type="text/javascript">  

document.write("JavaScript Hello World!");  

</script>  

#11. Define closure.

In JavaScript, we need closures when a variable which is defined outside the scope in reference is accessed from some inner scope.

var num = 10;  

function sum()   

{  

document.writeln(num+num);  

}   

sum();  

#12. Write a mul function which will produce the following outputs when invoked:

console.log(mul(2)(3)(4)); // output : 24
console.log(mul(4)(3)(4)); // output : 48

function mul (x)

{
   return function (y)

  { // anonymous function
       return function (z)

       { // anonymous function
           return x * y * z;
       };
   };
}

The mul function accepts the first argument and returns an anonymous function, which takes the second parameter and returns another anonymous function that will take the third parameter and return the multiplication of the arguments that have been passed.

We know that JavaScript, a function defined inside another one has access to the outer function's variables. Therefore, when a function is a first-class object it can be returned by other functions as well and be passed as an argument in another function.

#13. How to define an anonymous function?

An anonymous function can be defined in a similar way as a normal function. It would not have any name.

#14. What is a RESTful Web Service?

REST stands for Representational State Transfer.

It is an architectural style that has largely been adopted as a best practice for building web and mobile applications.

RESTful services are designed to be lightweight, easy to maintain, and scalable and are typically based on the HTTP protocol, make explicit use of HTTP methods (GET, POST, PUT, DELETE), are stateless, use intuitive URIs, and transfer XML/JSON data between the server and the client.

#15. What is an undefined value in JavaScript?

Undefined value means the

  • Variable used in the code doesn't exist
  • Variable is not assigned to any value
  • Property doesn't exist

#16. What are all the types of Pop up boxes available in JavaScript?

  • Alert
  • Confirm and
  • Prompt

#17. What is the use of Void(0)?

Void(0) is used to prevent the page from refreshing.

Parameter "zero" is passed while calling.

Void(0) is used to call another method without refreshing the page.

#18. Explain the differences between one-way data flow and two-way data binding.

In two-way data binding, changes to the UI and changes to the model occur asynchronously—a change on one end is reflected on the other. In one-way data binding, data only flows one way, and any changes that the user makes to the view will not be reflected in the model until the two are synced. Angular makes implementing two-way binding a snap, whereas React would be your framework of choice for deterministic one-way data flow.

#19. Mention what is the disadvantage of using innerHTML in JavaScript?

If you use innerHTML in JavaScript the disadvantage is

  • Content is replaced everywhere
  • We cannot use like "appending to innerHTML"
  • Even if you use +=like "innerHTML = innerHTML + 'html'" still the old content is replaced by html
  • The entire innerHTML content is re-parsed and builds into elements, therefore it’s much slower
  • The innerHTML does not provide validation and therefore we can potentially insert valid and broken HTML in the document and break it

#20. What is the use of Push method in JavaScript?

The push method is used to add or append one or more elements to the end of an Array. Using this method, we can append multiple elements by passing multiple arguments

#21. Which built-in method combines the text of two strings and returns a new string?

concat() method returns the character at the specified index.

#22. How can you get the reference of a caller function inside a function?

The arguments object has a callee property, which refers to the function you're inside of. For example −

function func() {
  return arguments.callee;
}
func();                // ==> func

Additional Questions:

There might be few questions like,

  1. What will the code below output to the console and why?
  2. Consider the two functions below. Will they both return the same thing? Why or why not?
  3. What will the code below output? Explain your answer.
  4. Consider the code snippet below. What will the console output be and why?

For such type of questions, you need to have a strong command over Javascript and its syntax. Always try to first understand the problem statement and then focus on the output.

Go through the past assignments you have done with the subject and make sure you are able to speak confidently on them. If you are fresher then interviewer does not expect you will answer very complex questions, rather you have to make your basics concepts very strong.

Here's another useful article for you, if you are Getting Ready For An Interview After Career Break.


15499551291549955129
Sainy Banerjee Pal
An engineer by profession but an ardent writer by heart, Sainy has been writing from the age of 12. She has a huge collection of her handwritten diaries. Her friends call her a therapist for broken hearts and can connect instantly with anyone. She lives with her doting husband who is also her critic for her write ups. Imaginative, spirited and filled with compassion, she always has a lot to say, to those who care to listen.


Share the Article :

Download App

Get The App

Experience the best of SHEROES - Download the Free Mobile APP Now!