October 3, 2018

Srikaanth

Wipro JavaScript Most Frequently Asked Latest Interview Questions Answers

What are the types of selectors in jQuery?

There are three types of selectors in jQuery:

CSS Selector
XPath Selector
Custom Selector

Enumerate the differences between Java and JavaScript?

Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for the different intent.  Java is an object – oriented programming (OOPS) or structured programming language like C++ or C whereas JavaScript is a client-side scripting language and it is said to be unstructured programming.

What are JavaScript types?

Following are the JavaScript types:
  • Number
  • String
  • Boolean
  • Function
  • Object
  • Null
  • Undefined
Wipro JavaScript Most Frequently Asked Latest Interview Questions Answers
Wipro JavaScript Most Frequently Asked Latest Interview Questions Answers

What is the use of isNaN function?

isNan function returns true if the argument is not a number otherwise it is false.

Between JavaScript and an ASP script, which is faster?

JavaScript is faster. JavaScript is a client-side language and thus it does not need the assistance of the web server to execute. On the other hand, ASP is a server-side language and hence is always slower than JavaScript.

javascript-code-snippet
Javascript

What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

Is it possible to break JavaScript Code into several lines?

Breaking within a string statement can be done by the use of a backslash, ‘\’, at the end of the first line

Example:

document.write("This is \a program");
And if you change to a new line when not within a string statement, then javaScript ignores break in line.

Example:


var x=1, y=2,

z=

x+y;
The above code is perfectly fine, though not advisable as it hampers debugging.

Which company developed JavaScript?

Netscape is the software company who developed JavaScript.

What are undeclared and undefined variables?

Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.

Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

Write the code for adding new elements dynamically?

<html>
<head> <title>t1</title>
<script type="text/javascript">
function addNode() { var newP = document.createElement("p");
var textNode = document.createTextNode(" This is a new text node");
newP.appendChild(textNode); document.getElementById("firstP").appendChild(newP); }
</script> </head>
<body> <p id="firstP">firstP<p> </body>
</html>

What is the difference between remove() and removeChild()?

The remove() function just removes the element. Whereas, the removeChild() returns the deleted element.

List out the Mouse Events.

There are altogether 9 mouse events. Here is the list:

1.    click: A single click

2.    dblclick: A double click

3.    mousedown: When the mouse button is clicked down.

4.    mouseup: When the mouse button is released up.

5.    mouseenter: When the mouse cursor enters an external element.

6.    mouseleave: When the mouse cursor leaves an external element.

7.    mouseover: When the mouse cursor enters an internal and external element.

8.    mouseout: When the mouse cursor leaves an internal and external element.

9.    mousemove: When the mouse cursor is moved.

What is the use of history object?

By using the history object you can change or switch back to history pages or forward from current page to another page.

What is an Event Bubbling in Javascript?

When an event is fired on an HTML element, the execution starts from that event and goes to its parent element. From there, the execution passes to its parent element and so on till the body element.

What does window.print() do in Javascript?

The print() function from window object prints the current web page when executed.

How can a Javascript code redirect the user to a different page?

The window.location is assigned a value; i.e., a web link. On its execution, the Javascript code can redirect the user to the mentioned web link.

What are Cookies in Javascript?

A Cookie is a variable that is stored on a client's/visitors machine. Using Cookies, the servers can identify the client and the client's transactions.

How do Javascript primitive/object types passed in functions?

Primitive types in Javascript are passed by value; whereas, object types are passed by reference.

What is NaN in Javascript?

NaN is a short form of Not a Number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN. A strange thing about NaN is that it is not equal to anything including itself.

List out all the falsifying tokens in Javascript.

There are 6 tokens that falsify in Javascript and they are false, null, undefined, 0, NaN.

What is Currying in Javascript?

A partial invocation of a Javascript function is called Currying. Few arguments of a function are processed and a function is returned. Few more arguments are added by the returning function.

When do we use JSON.stringify()?

The JSON.stringify() method is used to convert a Javascript data to a string.

What does unshift() function do in Javascript?



Just like push() which inserts elements into an array at the end of it, the unshift() function inserts elements at the beginning of an array.

What would the following lines of code output to the console?

console.log("0 || 1 = "+(0 || 1));
console.log("1 || 2 = "+(1 || 2));
console.log("0 && 1 = "+(0 && 1));
console.log("1 && 2 = "+(1 && 2));
Explain your answer.

The code will output the following four lines:

0 || 1 = 1
1 || 2 = 1
0 && 1 = 0
1 && 2 = 2
In JavaScript, both || and && are logical operators that return the first fully-determined “logical value” when evaluated from left to right.

The or (||) operator. In an expression of the form X||Y, X is first evaluated and interpreted as a boolean value. If this boolean value is true, then true (1) is returned and Y is not evaluated, since the “or” condition has already been satisfied. If this boolean value is “false”, though, we still don’t know if X||Y is true or false until we evaluate Y, and interpret it as a boolean value as well.

Accordingly, 0 || 1 evaluates to true (1), as does 1 || 2.

The and (&&) operator. In an expression of the form X&&Y, X is first evaluated and interpreted as a boolean value. If this boolean value is false, then false (0) is returned and Y is not evaluated, since the “and” condition has already failed. If this boolean value is “true”, though, we still don’t know if X&&Y is true or false until we evaluate Y, and interpret it as a boolean value as well.

However, the interesting thing with the && operator is that when an expression is evaluated as “true”, then the expression itself is returned. This is fine, since it counts as “true” in logical expressions, but also can be used to return that value when you care to do so. This explains why, somewhat surprisingly, 1 && 2 returns 2 (whereas you might it expect it to return true or 1).

What will be the output when the following code is executed? Explain.

console.log(false == '0')
console.log(false === '0')

The code will output:

true
false
In JavaScript, there are two sets of equality operators. The triple-equal operator === behaves like any traditional equality operator would: evaluates to true if the two expressions on either of its sides have the same type and the same value. The double-equal operator, however, tries to coerce the values before comparing them. It is therefore generally good practice to use the === rather than ==. The same holds true for !== vs !=.

What is the output out of the following code? Explain your answer.

var a={},
    b={key:'b'},
    c={key:'c'};

a[b]=123;
a[c]=456;

console.log(a[b]);

The output of this code will be 456 (not 123).

The reason for this is as follows: When setting an object property, JavaScript will implicitly stringify the parameter value. In this case, since b and c are both objects, they will both be converted to "[object Object]". As a result, a[b] anda[c] are both equivalent to a["[object Object]"] and can be used interchangeably. Therefore, setting or referencing a[c] is precisely the same as setting or referencing a[b].

What will the following code output to the console:

console.log((function f(n){return ((n > 1) ? n * f(n-1) : n)})(10));
Explain your answer.

The code will output the value of 10 factorial (i.e., 10!, or 3,628,800).

Here’s why:

The named function f() calls itself recursively, until it gets down to calling f(1) which simply returns 1. Here, therefore, is what this does:

f(1): returns n, which is 1
f(2): returns 2 * f(1), which is 2
f(3): returns 3 * f(2), which is 6
f(4): returns 4 * f(3), which is 24
f(5): returns 5 * f(4), which is 120
f(6): returns 6 * f(5), which is 720
f(7): returns 7 * f(6), which is 5040
f(8): returns 8 * f(7), which is 40320
f(9): returns 9 * f(8), which is 362880
f(10): returns 10 * f(9), which is 3628800

Consider the code snippet below. What will the console output be and why?

(function(x) {
    return (function(y) {
        console.log(x);
    })(2)
})(1);

The output will be 1, even though the value of x is never set in the inner function. Here’s why:

As explained in our JavaScript Hiring Guide, a closure is a function, along with all variables or functions that were in-scope at the time that the closure was created. In JavaScript, a closure is implemented as an “inner function”; i.e., a function defined within the body of another function. An important feature of closures is that an inner function still has access to the outer function’s variables.

Therefore, in this example, since x is not defined in the inner function, the scope of the outer function is searched for a defined variable x, which is found to have a value of 1.

Subscribe to get more Posts :