Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

60+ JavaScript Interview Questions, Exercises of Programming Languages

A list of 46 JavaScript interview questions and their answers. It covers topics such as data types, functions, timers, exceptions, arrays, objects, comments, and ES6 features. The document also explains the difference between let and var, attributes and properties, and event.preventDefault() and event.stopPropagation() methods. It defines terms such as hoisting, scope, closures, and promises. useful for students preparing for JavaScript interviews or exams, or for those who want to refresh their knowledge of JavaScript concepts.

Typology: Exercises

2022/2023

Available from 09/12/2022

technicalurvashi
technicalurvashi 🇮🇳

4 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Technical Urvashi
P
A
G
E
5
JavaScript Interview Questions
1) What are JavaScript Data Types?
Following are the JavaScript Data types:
Number
String
Boolean
Object
Undefined
2) What is the use of isNaN, typeof function?
isNan function returns true if the argument is not a number otherwise it is false.
'Typeof' is an operator which is used to return a string description of the type of a
variable.
3) What is a prompt box?
A prompt box is a box which allows the user to enter input by providing a text box.
Label and box will be provided to enter the text or number.
4) What is 'this' keyword in JavaScript?
The JavaScript this keyword refers to the object it belongs to. This has different
values depending on where it is used. In a method, this refers to the owner object
and in a function, this refers to the global object.
5) What is the difference between setTimeout() and setInterval() methods?
The setTimeout(function, delay) function is used to start a timer that calls a
particular function after the mentioned delay. The setInterval(function, delay)
function is used to repeatedly execute the given function in the mentioned delay and
only halts when cancelled.
6) What is the difference between == and === operator?
== is called as equality operator which returns true when the two operands are
having the same value.
=== is called as strict equality operator which returns true when the two operands
are having the same value and same type.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download 60+ JavaScript Interview Questions and more Exercises Programming Languages in PDF only on Docsity!

A

G

E

JavaScript Interview Questions

1) What are JavaScript Data Types?

Following are the JavaScript Data types:

● Number

● String

● Boolean

● Object

● Undefined

2) What is the use of isNaN, typeof function?

isNan function returns true if the argument is not a number otherwise it is false. 'Typeof' is an operator which is used to return a string description of the type of a variable.

3) What is a prompt box?

A prompt box is a box which allows the user to enter input by providing a text box. Label and box will be provided to enter the text or number.

4) What is 'this' keyword in JavaScript?

The JavaScript this keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.

5) What is the difference between setTimeout() and setInterval() methods?

The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled.

6) What is the difference between == and === operator?

== is called as equality operator which returns true when the two operands are having the same value. === is called as strict equality operator which returns true when the two operands are having the same value and same type.

A

G

E

7) How can the style/class of an element be changed?

It can be done in the following way: document.getElementById("myText").style.fontSize = "20"; or document.getElementById("myText").className = "anyclass";

8) What do mean by NULL in Javascript?

The NULL value is used to represent no value or no object. It implies no object or null string, no valid boolean value, no number and no array object.

9) 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

10) How to handle exceptions in JS?

Try… Catch---finally is used to handle exceptions in the JavaScript Try{ Code } Catch(exp){ Code to throw an exception } Finally{ Code runs either it finishes successfully or after catch }

11) What is the use of Push and Pop method in JavaScript?

The push method is used to add or append one or more elements to the end of an Array. The pop method is used to remove the last element from an Array.

A

G

E

● getElementsByTagName(‘tagname’): Gets all the elements that have the given tag name. ● querySelector(): This function takes css style selector and returns the first selected element.

18) What are the decodeURI() and encodeURI()?

EncodeURl() is used to convert URL into their hex coding. And DecodeURI() is used to convert the encoded URL back to normal.

19) What is a name function in JavaScript & how to define it?

A named function declares a name as soon as it is defined. It can be defined using function keyword as : Function named() { console.log(“Named function”); }

20) What are argument objects in JS?

JavaScript variable arguments represent the arguments that are passed to a function.

21) What are the scopes of a variable in JavaScript?

The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes. Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code. Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

22) What is Callback?

A callback is a plain JavaScript function passed to some method as an argument or option. It is a function that is to be executed after another function has finished executing, hence the name ‘ call back ‘. In JavaScript, functions are objects. Because of this, functions can take functions as arguments, and can be returned by other functions.

23) What is Closure?

Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope. It gives you access to an outer function’s

A

G

E

scope from an inner function. In JavaScript, closures are created every time a function is created. To use a closure, simply define a function inside another function and expose it.

24)What is the use of a Date object in JavaScript?

The JavaScript date object can be used to get a year, month and day. You can display a timer on the webpage by the help of JavaScript date object.

25) Differences between let and var?

Both let and var are used for variable and method declaration in JavaScript. However, the most important difference between the two JS keywords is that while the var keyword is function scoped, the let keyword is block scoped.

26) What is Anonymous function?

It is a function that has no name. These functions are declared dynamically at runtime using the function operator instead of the function declaration. The function operator is more flexible than a function declaration. It can be easily used in the place of an expression. For example: var display=function() { alert("Anonymous Function is invoked"); } display();

27) How to write a comment in JavaScript?

There are two types of comments in JavaScript.

  1. Single Line Comment: It is represented by // (double forward slash)
  2. Multi-Line Comment: Slash represents it with asterisk symbol as /* write comment here */

28) What does the isNaN() function?

The isNan() function returns true if the variable value is not a number.

29) What is the use of debugger keyword in JavaScript?

JavaScript debugger keyword sets the breakpoint through the code itself. The debugger stops the execution of the program at the position it is applied. Now, we

A

G

E

36) What is Scope?

Scope in JavaScript is the area where we have valid access to variables or functions. JavaScript has three types of Scopes. Global Scope , Function Scope , and Block Scope (ES6).

37) What is the prototype of an object?

A prototype in simplest terms is a blueprint of an object. It is used as a fallback for properties and methods if it does exist in the current object. It's the way to share properties and functionality between objects.

38) What projects have you worked on?

Explain about project you have worked on using HTML

39) What is the difference between ui & ui?

40) Where can you host your website?

41) From where can you buy a domain?

42) What are Closures?

43) What are Promises?

44)Mention some popular features of ES6?

ES6 features: let, const, arrow function, map function, spread operator, rest operator, class, destructuring, property shorthand, Modules, Template String, Arrow function, default function arguments, Array Helper Functions like filter, forEach, map, some, reduce, find, every.

45) Difference between Es5 & Es6?

Es5 : Es5 is the fifth edition of the ECMAScript, introduced in 2009.  Primitive data types that are string, boolean, number, null, and undefined are supported by Es5.  In Es5, we could define the variables by var keyword only.  Both function and return keywords are used to define a function in Es5.  In Es5, a for loop is used to iterate over elements.  Es6 : Es6 is the sixth edition of the ECMAScript, introduced in 2015.  For supporting unique values, a new primitive data type 'symbol' wasintroduced in Es6.  In Es6, in addition to var: let and const were introduced.  An arrow function is a newly added feature in Es6 in which we don't require the function keyword in order to declare the function.  Es6 introduced for..of loop in order to iterate over the values of the iterable objects.

46) What is destructuring?

It is a way to extract data from arrays and objects into a single variable. It is possible to extract smaller fragments from objects and arrays using this method. Basically, we

A

G

E

break our object and array elements into floating variables. For e.g: Run below code in your system. let color=['pink', 'blue']; let [c1, c2] = color; console.log (c1, c2);

47)What string Functions introduced in ES6?

startsWith, endsWith, includes, repeat

48)What are the object oriented features supported in ES6?

Explain class, objects, Inheritance, Methods here

49)Difference and Similarity between let & const?

Both let and const have block scope. let and const variable used before it is declared will give you error. Variables once declared with let and const keywod can't be redeclared with the same name again. let: variables declared with the let keyword are mutable, which means that their values can be changed. const: variables declared with the const keyword are block-scoped and immutable. When variables are declared with the const keyword, their value cannot be modified or reassigned. const doesn't define a constant value, but it defines constant reference to a value.

50)How to create a Class in Es6?

We use class keyword to create a class in Es6. Only functions and constructors are allowed in a class definition. Constructors in classes are responsible for initialising the properties of class's Objects. syntax: class className { }

51)What do you understand about default parameters?

If no value or undefined is passed, we can use the default parameters to set default values for named parameters. For e.g: Run below code in your system. const execute = (x , y = 2) => { console.log(x + " " + y); } execute(1);

52)What is a Temporal Dead Zone?

Variable Hoisting does not apply to let bindings in ES6, so let declarations do not rise to the top of the current execution. Hence, let and const variable used before it is declared will give you error (ReferenceError). From the beginning of the block until the initialization is performed, the variable is in a "temporal dead zone". For e.g: Run below code in your system. console.log(b); let b = 2;

53)Difference between Regular function & Arrow function?

Unlike regular functions, arrow functions do not have their own this. Arguments objects are not available in arrow functions, but are available in regular functions. Regular function can easily construct objects. arrow function cannot be used as a constructor. You can return values from the arrow function the same way as from a