December 22, 2018

Srikaanth

Apple Most Frequently Asked Latest JavaScript Interview Questions Answers

What are the types of post back in Ajax?

There are two types of post backs:

Synchronous Postback
Asynchronous Postback

How can we handle exception handling in Ajax?

ErrorTemplate which is the child tag of Script Manager is used to handle exception handling in Ajax.

What are the components of the ASP.NET Ajax Client Library?

Following components are used in Ajax client library:

Component Layer
Core Services Layer
Browser Compatibility Layer

What are the controls of the Script Management group?

The controls of script Management group are:

ScriptManager
ScriptManagerProxy
Apple Most Frequently Asked Latest JavaScript Interview Questions Answers
Apple Most Frequently Asked Latest JavaScript Interview Questions Answers

How many types of ready states in Ajax?

There are four ready states in Ajax:

Initialization
Request
Process
Ready

What is the difference between RegisterClientScriptBlock, RegisterClientScriptInclude and RegisterClientScriptResource?

Following are the functions:

RegisterClientScriptBlock – The script is specified as a string parameter.
RegisterClientScriptInclude – By setting the source attribute to a URL that point to a script file.
RegisterClientScriptResource – specifies Resource name in an assembly. The source attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.

What is called Variable typing in Javascript?

Variable typing is used to assign a number to a variable and the same variable can be assigned to a string.

Example

i = 10;

i = "string";
This is called variable typing.

How can you convert the string of any base to integer in JavaScript?

The parseInt() function is used to convert numbers between different bases. parseInt() takes the string to be converted as its first parameter, and the second parameter is the base of the given string.

In order to convert 4F (of base 16) to integer, the code used will be –

parseInt ("4F", 16);

Explain the difference between “==” and “===”?

“==” checks only for equality in value whereas “===” is a stricter equality test and returns false if either the value or the type of the two variables are different.

What would be the result of 3+2+”7″?

Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.

Explain how to detect the operating system on the client machine?

In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

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.

What is the function of delete operator?

The functionality of delete operator is used to delete all variables and objects in a program but it cannot delete variables declared with VAR keyword.

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

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

Alert
Confirm and
Prompt

What is the use of Void(0)?

Void(0) is used to prevent the page from refreshing and parameter “zero” is passed while calling.

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

How can a page be forced to load another page in JavaScript?

The following code has to be inserted to achieve the desired effect:

<script language="JavaScript" type="text/javascript" >

<!-- location.href="http://newhost/newpath/newfile.html"; //--></script>

Testing your this knowledge in JavaScript: What is the output of the following code?

var length = 10;
function fn() {
console.log(this.length);
}

var obj = {
  length: 5,
  method: function(fn) {
    fn();
    arguments[0]();
  }
};

obj.method(fn, 1);

Output:

10
2
Why isn’t it 10 and 5?

In the first place, as fn is passed as a parameter to the function method, the scope (this) of the function fn is window. var length = 10; is declared at the window level. It also can be accessed as window.length or length or this.length (when this === window.)

method is bound to Object obj, and obj.method is called with parameters fn and 1. Though method is accepting only one parameter, while invoking it has passed two parameters; the first is a function callback and other is just a number.

When fn() is called inside method, which was passed the function as a parameter at the global level, this.length will have access to var length = 10 (declared globally) not length = 5 as defined in Object obj.

Now, we know that we can access any number of arguments in a JavaScript function using the arguments[] array.

Hence arguments[0]() is nothing but calling fn(). Inside fn now, the scope of this function becomes the arguments array, and logging the length of arguments[] will return 2.

Hence the output will be as above.

Consider the following code. What will the output be, and why?

(function () {
    try {
        throw new Error();
    } catch (x) {
        var x = 1, y = 2;
        console.log(x);
    }
    console.log(x);
    console.log(y);
})();

1
undefined
2
var statements are hoisted (without their value initialization) to the top of the global or function scope it belongs to, even when it’s inside a with or catch block. However, the error’s identifier is only visible inside the catch block. It is equivalent to:

(function () {
    var x, y; // outer and hoisted
    try {
        throw new Error();
    } catch (x /* inner */) {
        x = 1; // inner x, not the outer one
        y = 2; // there is only one y, which is in the outer scope
        console.log(x /* inner */);
    }
    console.log(x);
    console.log(y);
})();

What will be the output of this code?

var x = 21;
var girl = function () {
    console.log(x);
    var x = 20;
};
girl ();

Neither 21, nor 20, the result is undefined

It’s because JavaScript initialization is not hoisted.



(Why doesn’t it show the global value of 21? The reason is that when the function is executed, it checks that there’s a local x variable present but doesn’t yet declare it, so it won’t look for global one.)

Subscribe to get more Posts :