JavaScript Interview Questions and Answers (294) - Page 3

Difference Json Arrary Vs Json Object ?

JSONArray

A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the values.

[ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]


JSONObject

A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names.

{"bindings": [

{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};

What is the difference of "setTimeout" function and setInterval functions in Javascript

setTimeout is only execute the function after the defined time in milleseconds, its execute only one time.

setInterval, will call the function in each time interval.
Is "Javascript" a case sensitive language ?

NOTE: This is objective type question, Please click question title for correct answer.
What is the difference between the below two statements:- (1) var myname = "Akiii"; (2) myname = "Akiii";

Both the above two statements are same. In javascript, even if you don't declare a "var" keyword, it is automatically added.

Note:-
It is always good to use "var" to declare any variable in javascript. It makes the code cleaner and readable.

Thanks and Regards
Akiii
What data type javascript supports?

Javascript supports only object data type.

Example

var variablename; //var is an object
What is isNaN in javascript?

isNaN is a function, it returns true if the argument is not a number.

Example:

var a="text";

var b=1234;
document.write(isNaN(a)) //it will return true
document.write(isNaN(b)) //returns false

How will you create new object in javascript?

In object variable, you can pass any value like stirng, integer.

var obj=new Object();

obj="my string";
document.write(obj);

How do you create array in javascript?

Using following code.

var arr=new Array();

arr[0]="dot";
arr[1]="net";
arr[2]="funda";

document.write(arr[0] + " " + arr[1] + " " + arr[2]);

How will you sort an array using javascript?

Using sort() function.

[code]var arr=new Array();
arr[0]="dot";
arr[1]="net";
arr[2]="funda";

arr.sort();
document.write(arr[0] + " " + arr[1] + " " + arr[2] );

output will be
dot funda net

[/code]
How to convert a string to float or number in javascript?

parseFloat() and parseInt() are the function to convert string to float and integer respectively.

Example:

parseInt("123.25");

parseFloat("123.25");

How will you submit form using javascript?

Using following line of code:


<script language="javascript">
documnet.formID.submit();
</script>
<form id="formID">
//your from controls here.....
</form>

How Will You Get Textbox Value in Javascript?

By Using This javascript Code ,We Can Get The Textbox Vlue...

var txt_value= document.getElementById('<%=TextBox1.ClientID%>').value;

Which event tests if a form field has changed?

NOTE: This is objective type question, Please click question title for correct answer.
A method is the object oriented version of

NOTE: This is objective type question, Please click question title for correct answer.
What debugging options does Netscape have?

NOTE: This is objective type question, Please click question title for correct answer.
How many different ways XSS attacks can occur?

XSS attacks can be categorized into following three categories:

1) Stored: The attack is saved into a persistent storage medium such as a database or file.

2) Reflected: Non-persistent attacks needing a delivery method to initiate the attack such an email or malicious form.

3) DOM based XSS: This attack manipulates the DOM to execute the attack payload. It is less well known.
How to write in browser page using javascript?

Using following lines of code:

<script type="text/javascript">

document.write("Hi, This is my page.");
</script>

How to change a label value using javascript?

Using following codes

<script type="text/javascript">

document.getElementById("labelID").innerHTML="Changed Label";
</script>

What is knockout ?

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.

Any time you have sections of UI that update dynamically, KO can help you implement it more simply and maintainable.

It works with any server or client-side technology.

Browser support : (IE 6+, Firefox 2+, Chrome, Safari, others)
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories