Computers & Accessories: Buy Computers & Accessories Online

Search Latest Price in

Breaking News

Java Script Interview questions part -1

Print Friendly and PDF

Ques: 1 How can JavaScript make a Web site easier to use?  That is, are there certain JavaScript techniques that make it easier for people to use a Web site?
Ans: JavaScript's greatest potential gift to a Web site is that scripts can make the page more immediately interactive, that is, interactive without having to submit every little thing to the server for a server program to re-render the page and send it back to the client. For example, consider a top-level navigation panel that has, say, six primary image map links into subsections of the Web site. With only a little bit of scripting, each map area can be instructed to pop up a more detailed list of links to the contents within a subsection whenever the user rolls the cursor atop a map area. With the help of that popup list of links, the user with a scriptable browser can bypass one intermediate menu page. The user without a scriptable browser (or who has disabled JavaScript) will have to drill down through a more traditional and time-consuming path to the desired content.
Ques: 2 What’s a way to append a value to an array?
Ans:arr[arr.length] = value; 
Ques: 3 How do you assign object properties?
Ans:obj["age"] = 17 or obj.age = 17. 
Ques: 4 How do you create a new object in JavaScript?
Ans:var obj = new Object(); or var obj = {};
Ques: 5 What looping structures are there in JavaScript?
Ans:for, while, do-while loops, but no foreach. 
Ques: 6 How about 2+5+"8"?
Ans:Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.
Ques: 7 What does "1"+2+4 evaluate to?
Ans:Since 1 is a string, everything is a string, so the result is 124.
Ques: 8 What boolean operators does JavaScript support?
Ans:&&, || and ! 
Ques: 9 What is negative infinity?
Ans:It’s a number in JavaScript, derived by dividing negative number by zero.
Ques: 10 How do you convert numbers between different bases in JavaScript?
Ans:Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal
3F to decimal, use parseInt ("3F", 16);
What does isNaN function do? - Return true if the argument is not a number.
Ques: 11 What are JavaScript types?
Ans:Number, String, Boolean, Function, Object, Null, Undefined.
Ques: 12 What’s relationship between JavaScript and ECMAScript?
Ans:ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3
Ques: 13 What does break and continue statements do?
Ans:Continue statement continues the current loop (if label not specified) in a new iteration whereas break statement exits the current loop.
Ques: 14 What does the delete operator do?
Ans:The delete operator is used to delete all the variables and objects used in the program ,but it does not delete variables declared with var keyword.
Ques: 15 What is === operator ?
Ans:==== is strict equality operator ,it returns true only when the two operands are having the same value without any type conversion.
Ques: 16 What are undefined and undeclared variables?
Ans: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.
Ques: 17 Does javascript have the concept level scope?
Ans: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.
Ques: 18 What is variable typing in javascript?
Ans:It is perfectly legal to assign a number to a variable and then assign a string to the same variable as follows example
i = 10;
i = "string";
This is called variable typing
Ques: 19 What is the difference between undefined value and null value?
Ans:A. Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null
B. typeof undefined variable or property returns undefined whereas typeof null value returns object
Ques: 20 What does undefined value mean in javascript?
Ans:Undefined value means the variable used in the code doesnt exist or is not assigned any value or the property doesnt exist.

No comments