Interview questions for java script

JavaScript also abbreviated as JS, is a high level server side programming language. JavaScript is widely used all over the world to build various web applications, which means there are huge opportunities available for the JavaScript programming. To build a career in JavaScript programming, candidates need to crack the interview in which they are asked for various JavaScript interview questions and answers.

1. Is JavaScript a case-sensitive language?

Yes, JavaScript is a case sensitive language. The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

2. Can you name two programming paradigms important for JavaScript app developers?

JavaScript is a multi-paradigm language, supportingimperative/procedural programming along with OOP (Object-Oriented Programming) and functional programming. JavaScript supports OOP with prototypal inheritance.
Good to hear:
• Prototypal inheritance (also: prototypes, OLOO).
• Functional programming (also: closures, first class functions, lambdas).

3. What are the advantages of JavaScript?

Following are the advantages of using JavaScript −
• Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
• Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.
• Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
• Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.

4. What is functional programming?

Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data. Lisp (specified in 1958) was among the first languages to support functional programming, and was heavily inspired by lambda calculus. Lisp and many Lisp family languages are still in common use today.
Functional programming is an essential concept in JavaScript (one of the two pillars of JavaScript). Several common functional utilities were added to JavaScript in ES5.

5. How can you create an object in JavaScript?

JavaScript supports Object concept very well. You can create an object using the object literal as follows −
1
2
3
4 var emp = {
name: “Daniel”,
age: 23
};

6. How can you create an Array in JavaScript?

You can define arrays using the array literal as follows-
1
2 var x = [];
var y = [1, 2, 3, 4, 5];

7. Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?

Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.
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. The clearInterval(id)function instructs the timer to stop.
Timers are operated within a single thread, and thus events might queue up, waiting to be executed.

8. What is the difference between classical inheritance and prototypal inheritance?

Class Inheritance: instances inherit from classes (like a blueprint — a description of the class), and create sub-class relationships: hierarchical class taxonomies. Instances are typically instantiated via constructor functions with the `new` keyword. Class inheritance may or may not use the `class` keyword from ES6.
Prototypal Inheritance: instances inherit directly from other objects. Instances are typically instantiated via factory functions or`Object.create()`. Instances may be composed from many different objects, allowing for easy selective inheritance.

9. 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 functionkeyword as :
1
2
3 function named(){
// write code here
}

10. Can you assign an anonymous function to a variable and pass it as an argument to another function?

Yes! An anonymous function can be assigned to a variable. It can also be passed as an argument to another function.
In case you are facing any challenges with these JavaScript Interview Questions, please comment on your problems in the section below.

11. What is argument objects in JavaScript & how to get the type of arguments passed to a function?

JavaScript variable arguments represents the arguments that are passed to a function. Usingtypeof operator, we can get the type of arguments passed to a function. For example −
1
2
3
4
5
6 function func(x){
console.log(typeof x, arguments.length);
}
func(); //==> “undefined”, 0
func(7); //==> “number”, 1
func(“1”, “2”, “3”); //==> “string”, 3

12. What are the pros and cons of functional programming vs object-oriented programming?

OOP Pros: It’s easy to understand the basic concept of objects and easy to interpret the meaning of method calls. OOP tends to use an imperative style rather than a declarative style, which reads like a straight-forward set of instructions for the computer to follow.
OOP Cons: OOP Typically depends on shared state. Objects and behaviors are typically tacked together on the same entity, which may be accessed at random by any number of functions with non-deterministic order, which may lead to undesirable behavior such as race conditions.
FP Pros: Using the functional paradigm, programmers avoid any shared state or side-effects, which eliminates bugs caused by multiple functions competing for the same resources. With features such as the availability of point-free style (aka tacit programming), functions tend to be radically simplified and easily recomposed for more generally reusable code compared to OOP.
FP also tends to favor declarative and denotational styles, which do not spell out step-by-step instructions for operations, but instead concentrate onwhat to do, letting the underlying functions take care of the how. This leaves tremendous latitude for refactoring and performance optimization, even allowing you to replace entire algorithms with more efficient ones with very little code change. (e.g., memoize, or use lazy evaluation in place of eager evaluation.)

leave your comment


Your email address will not be published. Required fields are marked *