Monday, 3 August 2015

23 - Javascript Interview questions


1. What is JavaScript?

Ans Javascript is a client-side scripting language that is understood by browsers.

2. What is the use of isNaN function?

Ans isNan() function returns true if the variable is not number otherwise it returns false.

3. Define this keyword in javascript.

Ans this keyword used to point the current object in the code.

4. Is JavaScript case sensitive?

Ans Yes

5. What is the syntax to use the external javascript file?

Ans.  <script type="text/javascript" src="test.js"></script>

6. How to write a comment in javascript?

Ans. 1. // test comment
        2. /* test comment */

7. How do you change the style/class on any element?

Ans. document.getElementById("Id").style.fontSize = "";
        -or-
        document.getElementById("Id").className = “anyclass”;

8.  What data types are supported in Javascript?

Ans. Number, String, Undefined, null, Boolean

9. How to disable control using Javascript?

Ans. document.getElementById("Id").disabled="true"

10. How to make control read-only using Javascript?

Ans. document.getElementById("Id").readOnly="true"

11. Which company developed JavaScript?

Ans. NetScape

12. How to submit a form using javascript?

Ans. using docuemnt.form[0].submit();

13. Explain the difference between "==" and "==="?

Ans. "==" check the equality only while "===" checks the equality as well as the type.

14. What would be the result of 4+3+"7"?

Ans. 77

15. What will be the output of the following ?

var x=10;
var y=x++;
var z=++x;
Ans. x=12 , y=10 , z=12.

16. What will be the output of the following?

0 == -0
Ans. true

17. What will be the output of the following?

var x;
if(typeof x === 'undefined')
Ans. true

18. How can we empty the array in javascript?

Ans. var array=['1','2','3'];
array=[];

19. How to check the object is an array or not?

Ans. using Array.isArray[array_variable]

20. What will be the output of the following condition?

Ans. if(Number("1")==1)
        {
        }
Ans. true

21. What is the use of Number.isInteger method?

Ans. Number.isInteger is used to check whether the value is number or not.
        For Example :
        if(Number.isInteger(1))
       {
       }
      This condition is true.

22. How can we read the properties of an object in Javascript?
Ans. using dot(.) notation.

23. What is the difference between "var" and "let" keywords?
Ans.  "var"  has function scope and "let" has block scope.

SQL server tricky questions