Java Script

Interview Questions on Java Script

31. What is function in javascript?

Def :- Set of statements to perform a particular operation.
Syntax :- 
function function_name(arg1,arg2){
//body
}
Ex :- 
function myFunction(p1, p2) {
    return p1 * p2;   
    // The function returns the product of p1 and p2
}

32. Can we access local variable out side the function?

No. they are permitted to that function only.

33. How to create global variables?

Create variables outside function.

34. How to execute javascript function when particular button clicked?

Use onclick attribute.
Ex:- <button onclick=”functionname”> Button1 </buttuon>.

35. How to execute javascript function when form is submitted?

Use onsubmit attribute.
Ex:- <button onsubmit=”functionname”> OK </buttuon>.

36. How to execute function when mouse over on hyperlik?

use onmouseover attribute. 
<a href='index.html' 
    onmouseover='this.style.textDecoration="none"' 
    onmouseout='this.style.textDecoration="underline"'>
    Click Me
</a>

37. How to execute function when mouse leaves on hyperlik?

use onmouseout attribute. 
<a href='index.html' 
    onmouseover='this.style.textDecoration="none"' 
    onmouseout='this.style.textDecoration="underline"'>
    Click Me
</a>

38. How to execute function select option from dropdown list?

Use onchange attribute.
Ex :-
<select id="leave" onchange="changeMessage()" >
  <option value="5">Get Married</option>
  <option value="100">Have a Baby</option>
  <option value="90">Adopt a Child</option>
</select>

39. Create vehicle object which has type, model and color values?

var car = {type:"Fiat", model:500, color:"white"};

40. How to access members of object variable?

Syntax :-  objectname.keyname
Ex:- var color = car.color;
41. What are the uses of javascript?
1. For client side validations.
2. Tomake interactive effects within the browser.
3. To make request and load response in div without loading entire page.

www.000webhost.com