JAVASCRIPT Programming Questions & Answers

Explore model answers categorized by subjects like Java, HTML, DBMS, and more.

JAVASCRIPT Programming Questions & Answers

What is the JavaScript?

Answer:
 JavaScript is an scripting language for the client side web development means web pages. It is designed by Brenden Eich comes in 1995.

Developer of JavaScripts are Netscape Communications Corporation, Mozilla Foundation. As name indicate you think it is essential related to Java. Its wrong its syntax matched with C Syntax,it use some java name and their convension. It is influenced by Seff,C,Scheme,Perl,Python,Java. Using this we can do many thimgs like: to improve Design,validate forms,detect browsers etc. JavaScript can be use by new programmer easily. I have given you some most important point related to JavaScript. 

  1. JavaScript is a trademark of Sun Microsystem. 
  2. It is dynamic,Weak and prototype language. 
  3. Using JavaScript we can make our HTML pages interactive. 
  4. JavaScript is a scripting language.
  5. We can embedded JavaScript directly into HTML pages.
  6. It is an interpreted language means for execution their is no need to pre-compilation of JavaScript. Latest version of JavaScript is 1.8/ 2008

What do mean by NULL in Javascript?

Answer:
The NULL value is used to represent no value or no object. 
mean No object or null string, No valid boolean value, No number , No array object

Is Java and JavaScript are same or not?

Answer:

 No, they are not.

Java (developed by Sun Microsystems) is a powerful and much more complex programming language in the same category as C and C++.

JavaScriptwas created by Brendan Eich at Netscape and was first introduced in December 1995 under the name of LiveScript. However, it was rather quickly renamed JavaScript, although JavaScripts official name is ECMAScript, which is developed and maintained by theECMA (European Computer Manufacturer\'s Association) International organization.

When we use JavaScript?

Answer:
We use JavaScript when we want to perform several things like this

  1. JavaScripts are simple pre compiled code.We use this code into the HTML pages to make interactive .It is easy to use. 
  2. Using JavaScript we can set dynamic text into the HTML page.Example:document.write(\"+text+\") 
  3. we can also set JavaSCript perform when some event happen means its automatically call when some special event execute.
  4. Using JavaScript we can read HTML element and changed the content of element. 
  5. Using JavaScript we can validate the data before sending to to the server.Means that we can reduce the server Urocessing before using JavaScript. 
  6. Using JavaScript we can identify the user\'s browser. 
  7. Using JavaScript we can also create the cookie and used this cookies to store and retrieve info on user\'s system.

What are you understand about ECMAScript?

Answer:
  1. ECMAScript is an official name of JavaScript.
  2. ECMA Organization developed and maintain ECMAScript.
  3. An official JavaScript standard is ECMA-262.Development to of this started in 1996 and It is first used in ECMA     General Assembly in june 1996.
  4. It gets cettificated by international ISO (ISO/IEC 16262) standard in 1998.
  5. It is usually based on JavaScript and Jscript Repectively given by Netscape and Microsoft.First it is invented by   Brendan Eich at Netscape and applied on Navigator 2.0 after 1996 it is used on all type of Netscape and     micrisoft   browser.

How to use JavaScript on HTML pages?

Answer:
 We use JavaScript in HTml page inside the 


 In the above example we write JavaScript inside the 
Those we write inside the document.write it will print as output. 
Output:
R4R Welcomes you on that place where professtionals meet.

How to use comments in JavaScript?

Answer:
 When you use JavaScript in HTML pages.But keep this in mind bwoser that we used in Html doesn't support to show javaScript as page content.We used HTML comment tage to hide the JavaScript. We start comment tag() after the last JavaScript line.//is the JavaScript comment symbol.
Example:








    

In HTML where JavaScript will executed?

Answer:
When we write javaScripts inside the body that will execute when page load.If we write JavaScripts inside the head than it willexecuted when we called. When we put JavaScript with in head of HTML.Than JavaScript is executed when we called them.

Example:

/*Their is no limit to put a fixed number of JavaScripts on your page.You can use JavaScripts in both head and body together.*/<html><head><script type=\"text/javascript\">........</script></head><body><script type=\"text/javascript\">........</script></body>

How to use an External JavaScript?

Answer:
 We use external JavaScript when we want to execute same JavaScripts on many pages.When we use external JavaScript using this their is no need to write JavaScripts on every page.
  If we want to use JavaScript than we first write JavaScript in enternal file than save this external JavaScript file by using .js file extension.
 External Script doesn\'t contain 





Is JavaScript Case-Sensitive or not?

Answer:
 JavaScript is an Case-Sensitive scripting language. It means keep your eyes open when you write JavaScript Statement,create or call variables,functions and objects.

Example:

     $var=10;

     $VAR=10;

Both variable show diffrent value.

How you define JavaScript Statement?

Answer:
 JavaScripts called as a sequence of Statement those are executed on browser.We use javaScript Statement to say the browser what to write.
Example:
document.write("R4R Welcomes You!");
 Using above Statement we say browser to write R4R Welcomes You! on browser.We distinguish each javaScript Statement by semicolon(;).

How you define JavaScript Code?

Answer:

we can define JavaScript as a sequence of JavaScript Statements.Statement write in JavaScript Code executed one by one in order they have written.
Example:

  1. <script type=\"text/javascript\">
  2. document.write(\"<h1>Here you write header</h1>\");
  3. document.write(\"<p>Here write your first paragraph</p>\");
  4. document.write(\"<p>Here write your second paragraph</p>\");
  5. </script>

What is JavaScript?

Answer:
JavaScript is a platform-independent,event-driven, interpreted client-side scripting and programming language developed by Netscape Communications Corp. and Sun Microsystems.

How to detect the operating system on the client machine?

Answer:
 In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

How to read and write a file using javascript?

Answer:
I/O operations like reading or writing a file is not possible with client-side javascript. However , this can be done by coding a Java applet
that reads files for the script.

How you define JavaScript Blocks?

Answer:
 We can grouped JavaScript Statements into Blocks.We use Blocks when we want that some Statement will execute together.We open Blocks with left curly bracket'{' and ends with write curly bracket'}'.
Example:


Where are cookies actually stored on the hard disk?

Answer:
This depends on the user's browser and OS.
In the case of Netscape with Windows OS, all the cookies are stored in a single file called cookies.txt
c:\Program Files\Netscape\Users\username\cookies.txt
In the case of IE,each cookie is stored in a separate file namely username@website.txt.
c:\Windows\Cookies\username@Website.txt

How we use JavaScript Comments?

Answer:
 
 Generally, We use Comments in JavaScript to make JavaScipts easily understand.We start to write single line comment by //.Example:<script type=\"text/javascript\">// Here write the header:document.write(\"<h1>This is my header</h1>\");// Below I have write two paragraphs:document.write(\"<p>This is my first paragraph</p>\");document.write(\"<p>This is my second paragraph </p>\");</script> We can write multiline comment on JavaScript also.We start to write multi line comment with /* and ends with */.Example:<script type=\"text/javascript\">/*Here I have write one header and two paragraphs*/document.write(\"<h1>This is my header</h1>\");document.write(\"<p>This is my first paragraph </p>\");document.write(\"<p>This is my second paragraph </p>\");</script>
 We can stop execution of some code by using comments like that,
//document.write("<p>This is my first paragraph.</p>");
 We can also write comments on the end of the line.
document.write("Hello");//This statement will write Hello.
document.write("World");//This statement will write World.
 

What can javascript programs do?

Answer:
Generation of HTML pages on-the-fly without accessing the Web server. The user can be given control over the browser like User input validation Simple computations can be performed on the client's machine The user's browser, OS, screen size, etc. can be detected Date and Time Handling

How you define Javascript Variable?

Answer:
 We Variable in javaScript to store information. 

Variables may be of single character or group of characters. I have given you rules using them you can use variables in JavaScript.

 1.In JavaScript variables are case-sensitive means xand X both are different variables in case of JavaScript.  2.Keep in mind JavaScript should begin with a letter or underscore\'_\'.

How to set a HTML document's background color?

Answer:
document.bgcolor property can be set to any appropriate color
e.g.
document.bgcolor=#ffff;

How to create variable and assign value to those variables in JavaScript?

Answer:
  Below I have given how to create variables and assign values in Javascript.

 Example:var v;var variablename; Here,I have only declare(created) variables not assigning any values to them.  var v=7;var variablename=\"xyz\"; Here, I have assign the values to both variables are 7 and xyz respectively. 

We assign number without quotes and if want to assign text to variables than write text with in quotes.

 InJavaScript When you assign the values to the variables without declaring them.javaScript automatically declare the variable.Example: Here,we assign the value to v and variablename with declaring them.v=7;variablename=\"xyz\"; Than it will work as same as,var v=7;var variablename=\"xyz\"; 

 JavaScript give us facility to Redeclare JavaScript Variable without loosing data that variables have already contain. we can also perform arithmetic operations with JavaScript variables. a=9;b=a-7;

What is reason of the "Access is Denied" ?

Answer:
The "Access Denied" error in any browser is due to the following reason.
A javascript in one window or frame is tries to access another window or frame whose document's domain is different from the document containing the script

Is a javascript script faster than an ASP script?

Answer:
Yes. 
Since javascript is a client-side script it does require the web server's help for its computation,so it is always faster than any server-side script like ASP,PHP,JSP etc.

How you define JavaScript Operator?

Answer:
 We use operator to assign(\"=\") and add(\"+\") values. 

Using Airthmetic Operators we can perform some airthmetic operation like this.

 if y=5

 Addition x=y+4 x=9-

 Subtraction x=y-4 x=1 

 Multiplication x=y*2 x=10

 Division x=y/2 x=2.5 

 Modulus x=y%2 x=1 

 Increment x=++y x=6 

 Decrement x=--y x=4 


Are Java and JavaScript the Same?

Answer:
No. 
Java and javascript are two different languages.
Java is a powerful object - oriented programming language like C++,C whereas Javascript is a client-side scripting language with some limitations.

How to embed javascript in a web page?

Answer:
javascript code can be embedded in a web page between
  tags

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

Answer:
This can be achieved by using the following tag between head tags or between body tags.

where abc.js is the external javscript file to be accessed.

What is the difference between an alert box and a confirmation box?

Answer:
An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.

How you define Comparison and Logical Operators?

Answer:
  Using Camparison and Logical Operator we test and gives result in the form of true or false

.I have given some comparison operators with their describtion.== is equal to

 === is exactly equal to

 != is not equal to 

> is greater than 

is less than

 >= is greater than or equal to

 <= is less than or equal to

 Example: 

if (gender==M) document.write(\"he is a male\");

 Logical Operator: We use logical operators to find out the logic between variables or values.Let, x=6 and y=3, logical operators: && and (x < 10 && y > 1) is true

 || or (x==5 || y==5) is false 

! not !(x==y) is true

 Conditional Operator: Using conditional operater we can assign the resultant value to the variable.Syntax:variablename=(condition)?val1:val2

 Example:welcome=(user==\"Professional\")?\"Dear Professional \":\"Dear \"; If the user is equal to professional then Dear Professional is assign to the welcome otherwise Dear assign to the welcome.

What is a prompt box?

Answer:
A prompt box allows the user to enter input by providing a text box.

Can javascript code be broken in different lines?

Answer:
Breaking is possible within a string statement by using a backslash \ at the end but not within any other javascript
statement.that is ,
document.write("Hello \
world");
is possible but not
document.write \
("hello world");

How to hide javascript code from old browsers that dont run it?

Answer:
Use the below specified style of comments