Tuesday, August 19, 2014

JavaScript

JavaScript interview 

1)  What's relationship between JavaScript and ecmascript?
2). What are JavaScript types?
3) How do you convert numbers between different bases in JavaScript?
4) What does isNaN function do?
5). What is negative infinity?
6) What boolean operators does JavaScript support?
7) What looping structures are there in JavaScript?
8) How do you create a new object in JavaScript?
9)  How do you assign object properties?
10) Whats way to append value to the array?
11)  What is this keyword?
12). What does "1"+2+4 evaluate to? 
13). What is javascript?
14)  How do you submit form using JavaScript?
15).  How to get javascript onto the web page?
16).  How to read and write a file using javascript?
17).  How to detect operationing system on the client machine?
18).  How to create arrays in Javascript?
19).  Where are cookies actually stored on the hard disk?
20) What is negative infinity?
21).  What is the data type of variables in javascript?
22). Methods GET and POST in HTML forms- what is the difference?
23). What does "Access is denied " IE error mean?
24). Is Javascript faster than ASP script?
25)   How to embed javascript in a web page?
26). What are the problems associated with using Javascript?
27). How to get contents of input box using javascript?
28). How to determine state of the checkbox using javascript?
29). How to access external javascipt file that is stored externally and not embedded?
30). What is the difference between alert box and confirmation box?
31).  What is prompt box?
32). Can javascript code be broken in different lines?
33) How about 2+5+"8"?
34). What is the difference between session state and view state?
35). How to access elements using javascript?
36). What looping structures are there in Javascript?
37). Name the numeric constants representing max,min values
38). What does javascript null mean?
39). How do you create new object in Javascript?
40). How do you assign object properties
41). Whats the way to append value to the array
42). What does undefined value mean in javascript?
43). What is the difference between undefined value and null value?
44). What is variable typing in javascript?
45). Does javascript have concept level scope?
46). What is undefined and undeclared variable?
47). What is === operator?
48). How disable an HTML object?
49). How to create a popup warning box
50). How to create a confirmation box?
51). How to create an input box?
52). How to reload the current page?
53). T How to force a page to go to another page usng Javascript?
54). How to convert string to a number using javascript?
55) How to test for bad numbers using Javascript?
56). What does the delete operator do?

What's relationship between JavaScript and ecmascript?
- ecmascript is yet another name for JavaScript

What are JavaScript types?

- number, string, boolean, function, object, null, undefined.

How do you convert numbers between different bases in JavaScript?
- use the parseInt() function, this takes string as first parameter and the base as second parameter.

What does isNaN function do?
- return true if the argument is not a number.

What is negative infinity?
- it's number in JavaScript, derived by dividing negative number by zero

What boolean operators does JavaScript support?

- &&' || and !

What looping structures are there in JavaScript?

- for, while, do-while loops, but no reach

How do you create a new object in JavaScript?

- var obj= new object();
Or
Var obj={};

How do you assign object properties?
- obj.age=17

Whats way to append value to the array?
- arr[arr.length]=value

What is this keyword?

- It refers to the current object.

What does "1"+2+4 evaluate to?

- since 1 is a string, everything is a string, so result is 124

What is javascript?

- javascript is general purpose programming language designed to let programmers of all skill levels  control the behavior of software object.
- javascript is platform independent, event driven, interpreted client side scripting and programming language developed by netscape communications corp and sun microsystems.

How do you submit form using javscript?

- use document.forms[0].submit()

How to get javascript onto the web page?

- you can use several different methods of placing javascript in your web page.
- you can directly add a script element inside the body of page.
- javascript can be placed inside the <head> element
Functions and global variables typically reside inside the <head> element.

How to read and write a file using javascript?
- I/O operations like reading and writing a file is not possible with client side javascript.
- this can be done by coding a java applet that reads files for the script.

How to detect operating system on the client machine?
- in order to detect operating system on the client machine, navigator.appVersion string(property) should be used.

How to create arrays in Javascript?

- we can declare an array like this
Var scripts= new Array();
We can add elements to this array like this
Scripts[0]= "PHP"
scripts[1]="ASP"
scripts[2]="Javascript"

Where are cookies actually stored on the hard disk?

- this depends on the users browser and OS.
- in case of netscape with windows OS, all the cookies are stored in single file called cookies.txt
- c:\program files\netscape\users\username\cookies.txt
In the case of IE, each cookie is stored in separate file namely username@website.txt
c:\windows\cookies\username@website.txt

What is the data type of variables in javascript?
- all variables are of object type in javascript.

Methods GET and POST in HTML forms- what is the difference?
- GET: parameters are passed in query string, maximum amount of data that can be sent via GET method is limited to about 2kb
- POST: parameters are passed in request body. There is no limit to amount of data that can be transferred using POST. However, there are limits on the maximum amount of data that can be transferred in one name/value pairs.

What does "Access is denied " IE error mean?

- javascript in one window or frame tries to access another window or frame whose documents domain is different from document containing the script.

Is Javascript faster than ASP script?

- Yes. Since javascript is client side script it does require web servers help for its computation, so it is always faster than any server side script like ASP,PHP etc.

How to embed javascript in a web page?
- javascript code can be embedded in web page between <script language="javascript"></script>
Tags

What are the problems associated with using Javascript?

- browser version incompatibility is biggest problem.
- second biggest can of worms is scripting connections between multiple windows. Tend to avoid multiple windows that interact with each other

How to get contents of input box using javascript?
- use the value property
Var myValue= window.document.getElementById("myTextBox"). Value

How to determine state of the checkbox using javascript?
- var checkedP= window.document.getElementById("myCheckbox"). Checked.

How to access external javascipt file that is stored externally and not embedded?

- this can be achieved by using following tags between head tags or body tags
<script src="abc.js"></script>

What is the difference between alert box and confirmation box?

- an alert box displays only one button which is OK button whereas Confirm box displays two buttons namely OK and CANCEL

What is prompt box?

- prompt box allows user to enter input by providing a text box.

Can javascript code be broken in different lines?

- breaking is possible using string statement by using backslash\ at the end but not within any other javascript statement.
That is 
Document.write("hello \ world")
is possible but not document.write\

How about 2+5+"8"?

- since 2 and 5 are integers, this is number arithmetic, since 8 is string, its concatenation, so 78 is the result.

What is the difference between session state and view state?
- viewstate is specific to page in the session. 
- session state refers to user specific data that can be accessed across all pages in the web application.

How to access elements using javascript?

- we can use "getElementById" method 
Document.getElementbyId("useless").style.color="red"

Name the numeric constants representing max,min values

- Number.MAX_VALUE
- Number.MIN_VALUE

What does javascript null mean?

- null value is unique value corresponding no value or no object,



What does undefined value mean in javascript?

- undefined value means the variable used in the code doesnt exist or is not assigned any value or the property doesnt exist.

What is the difference between undefined value and null value?

- undefined value cannot be explicitly stated that is there in no keyword called undefined whereas null value has keyword called null
- typeof undefined variable or property returns undefined whereas typeof null value returns object.

What is variable typing in javascript?

- it is perfectly legal to assign a number to a variable and then assign a string to same variable as follows
Ex
I=10
I="string"
This is called variable typing.

Does javascript have concept level scope?

- no, javascript does not have block level scope, all the variables declared inside the function possess same level of scope unlike c,c++

What is undefined and undeclared variable?

- undeclared variables are those that are not declared in program, trying to read their values gives runtime error.
Undefined variables are those that are not assigned any value but are declared in the program. Trying to reach such variables gives special value called undefined value.

What is === operator?

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

How disable an HTML object?

- document.getElementbyId("myObject").disabled=true.

How to create a popup warning box?

- alert("warning: please enter an integer between 0 and 100")

How to create a confirmation box?

- confirm(" do you really want to launch the missile?");

How to create an input box?

- prompt("what is your temperature")

How to reload the current page?

- window.location.reload(true)

How to force a page to go to another page usng Javascript?

- <script language="JAVASCRIPT" type="text/javascript">
<!--location.href="http://newhost/newpath/newfile.html";//-->
</script>

How to convert string to a number using javascript?

- you can use parseInt() and parsefloat() methods.

How to test for bad numbers using Javascript?

- isNaN() can tell if number has gone bad.

What does the delete operator do?

- used to delete all variables and objects within the program, but it does not delete variables declated with var keyword.

No comments:

Post a Comment