Sunday, October 25, 2015

Javascript Interview Questions and Answers

11) What is “SetTimeOut” function in javascript?
“SetTimeOut” function is used to call the function given as a parameter after some time delay. Below is the javascript code for the same –
setTimeout(function(){ alert("Text to Show"); }, 5000);
12) What is “SetInterval” function in javascript?
“SetInterval” function is used to call the function (given as a parameter) repeatedly after some time delay. Below is the javascript code for the same –
setInterval (function(){ alert("Text to Show"); }, 5000);
13) What is “ClearInterval” function in javascript?
“ClearInterval” function is used to clear the time set from function – “SetInterval()”.
14) How to give comments in javascript?
  • For single line comment – “//”
  • For multi-line comments – “/* */”
15) Why to use “===” operator in javascript?
“===” operator is called strict operator and it returns true when both the values are same and returns false when the values are not same.

16) How we can submit a form using javascript?
For submitting a form from javascript we have to use – document.form[0].submit() method.
17) Will javascript support automatic conversion of type?
Yes javascript will support automatic conversion of type.
18) How we can change the style of an element from javascript?
Below code can be used to change the style of an element –
document.getElementByID(‘mytestid’).className = “testclass”;
19) How we can change the fontsize from javascript?
Below code can be used to change the font size –
document.getElementByID(‘mytestid’).style.fontsize = “12”;
20) How we can read and write file in javascript?
Below are the ways to read and write files in javascript –
  • Using Active X objects
  • Using Javascript Extension

No comments: