JavaScript Interview Questions and Answers (294) - Page 12

How to disable HTML objects?

By using document.getElementById("id").disable = true we can disable the Html objects.
What is the difference between undefined and null?

If a variable with no value is undefined that means the variable has not been initialized.
If the variable initialized with empty value, that is null.
How to get content of a textbox using javascript?

To get the contents of input box in java script we are using below sentence.
var content =Window.document.getElementById("inputBox Id").value;

Which tag is an extension to HTML that can enclose any number of JavaScript statements?

NOTE: This is objective type question, Please click question title for correct answer.
Which Of the following technologies,which option provides the ability to dynamically interact with Web page layout?

NOTE: This is objective type question, Please click question title for correct answer.
Tell us about DOM features?

With the help of Document object model,JavaScript creates dynamic HTML.

JavaScript can change all the HTML elements on the page.
JavaScript can change all the HTML attributes in the page.
JavaScript can change all the CSS styles in the page.
JavaScript can remove existing HTML elements and attributes.
JavaScript can add new HTML elements and attributes.
JavaScript can react to all existing HTML events in the page.
JavaScript can create new HTML events in the page.
How to open a new Window using Javascript function from a Link button or an anchor tag?

VB.Net
link.Attributes("onClick") = "window.open('url','name','properties')"

C#
link.Attributes["onClick"] = "window.open('url','name','properties')";

How to open a browser window with Maximum Size?

Use the fullscreen features of windows open method .It has yes and no option .Use below code:-
Button2.Attributes.Add("onclick", "window.open('Default2.aspx','','fullscreen=yes')");

How to check whether the Browser supports Javascript or not through Javascript?

Actually we can not check using Javascript if the browser is configured to use Javascript because obviously it can not run.
So instead we can use a <noscript> tag.<noscript> tag will always appear when Javascript is not supported
and therefore we can put information within this tag to warn the user to enable Javascript on their browser.
For Example:-
<noscript>

......
</noscript>

What is the calling order of components when angular js application starts?

If app is an angular module,
calling order is
app.config()
app.run()
directive's compile functions (if they are found in the dom)
app.controller()
directive's link functions (again if found)
How to get an HTML table rows count if we do not have tbody on HTML layout?

Write below code:-
var table_rows_cnt = document.getElementById('your_table_id').getElementsByTagName("tr").length;

alert(table_rows_cnt);

Or you can also write:-
var table_rows_cnt = document.getElementById('your_table_id').rows.length;

alert(table_rows_cnt);

How to get an HTML table rows count when it contains tbody on HTML layout?

We can write below code:-
var table_rows_cnt = document.getElementById('your_table_id').getElementsByTagName('tbody')[0].getElementsByTagName('tr').length;

alert(table_rows_cnt);

What do we mean by typeof operator?

The typeof operator is an in-built operator and is used to identify the type of an object.
It always returns a String value,so we should always compare return value to a string.
typeof is an operand and not a function.
Give an example of typeof operator?

typeof 25;        

Output :- number
typeof true;
Output :- boolean
typeof undefined;
Output :- undefined
typeof {};
Output :- object

How to call typeof operand with parentheses?

As typeof is an operand and not a function,that is the reason,the second method is actually not a function call.
Operation in parentheses are evaluated and then passed to typeof.

typeof(20);

Output :- number
typeof(true);

Output :- boolean
How to disable Enter key pressed inside TextBox to avoid submission or Postback through Javascript?

Write below Javascript function and call below function on onkeydown event in textbox definition as:-
function prevent_submission()

{
return (event.keyCode!=13);
}
<asp:TextBox ID = "txt_emp_first_name"
runat = "server"
onkeydown = "prevent_submission();"></asp:TextBox>

Which event is fired when we close browser?

NOTE: This is objective type question, Please click question title for correct answer.
Which Tag is used to enclose any number of JavaScript statements on a Page?

NOTE: This is objective type question, Please click question title for correct answer.
Which is the correct way to write a JavaScript Array?

NOTE: This is objective type question, Please click question title for correct answer.
What does the <noscript> tag do on a Page?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories