Set - 5

Question 6 :

Does javascript have the concept level scope?

Answer :

No. JavaScript does not have block level scope, all the variables declared inside a function possess the same level of scope unlike c,c++,java.


Question 7 :

What are undefined and undeclared variables?

Answer :

Undeclared variables are those that are not declared in the program (do not exist at all),trying to read their values gives runtime error.But if undeclared variables are assigned then implicit declaration is done .
Undefined variables are those that are not assigned any value but are declared in the program.Trying to read such variables gives special value called undefined value.


Question 8 :

What is === operator ?

Answer :

==== is strict equality operator ,it returns true only when the two operands are having the same value without any type conversion.


Question 9 :

How to find the selected radio button immediately using the 'this' variable?

Answer :

<script>
	function favAnimal(button) {
		alert('You like '+button.value+'s.');
	}
</script>
<input type="radio" name="marsupial" value="kangaroo" onchange="favAnimal(this)">Kangaroo <br />
<input type="radio" name="marsupial" value="Opossum" onchange="favAnimal(this)">Opossum <br />
<input type="radio" name="marsupial" value="Tasmanian Tiger" onchange="favAnimal(this)">Tasmanian Tiger

 


Question 10 :

How to find radio button selection when a form is submitted?

Answer :

<script type="text/javascript"> 
	function findButton() {
		var myForm = document.forms.animalForm;
		var i;
		for(i=0;i<myForm.marsupial.length; i++) {
			if(myForm.marsupial[i].checked) {
				break;
			}
		}
		alert("You selected \""+myForm.marsupial[i].value+"\".");
	}
</script>
<form name="animalForm" action="">
<input type="radio" name="marsupial" value="kangaroo" />Kangaroo <br />
<input type="radio" name="marsupial" value="Opossum" />Opossum <br />
<input type="radio" name="marsupial" value="Tasmanian Tiger" />Tasmanian Tiger
<input type="button" name="GO" value="GO" onClick="findButton()" />