How you define Popup Boxes in JavaScript?

How you define Popup Boxes in JavaScript?
 In JavaScript we only can make three type of Popup Boxes.

These are Alert Box,Confirm box and Prompt Box.

 Alert Box: We use Alert boxe in that case where want check the information those given by user.When Alert box                      popup comes user should press \'ok\' to execute this page.Syntax:alert(\"anytext\"); 

 Confirm Box: Use this box we want to verfy or accept something from user.Syntax:confirm(\"anytext\"); 

 Prompt Box: Use when we want user to input a value before entering a page. When Alert box popup comes user                      should press \'ok\' to proceed than after entering an input value.syntax:(\"anytext\",\"defaultvalue\")                       

 

More interview questions and answers

How to use throw statement in JavaScript?

 We can create an Exception by using JavaScript.We used throw with try..catch block.Than we find out the more accurate result message.Syntax:throw(exception) This exception may be a string, integer, Boolean or an object.

Example:

try {

        throw new Error(200, \"x equals zero\");

}

catch (e) {

    document.write(e.message);

Output: x equals zero.

How to use Methods in JavaScript?

We know that methods are the actions that we performed on the objects.
Here,I use a toLowerCase() method to change the text of a string object into the lowercase letters.<script type=\"text/javascript\">
var str=\"Hello world!\";
document.write(str.toLowerCase());
</script>
Output:hello world!
 

JavaScript is an Object Oriented Programming language or not?

 Yes, We can say that JavaScript is an Object Oriented Programming Language.So,It is able to make own objects and variable types.

We know that properties are the values associated with an JavaScript

Example:

<script type=\"text/javascript\">

var txt=\"Hello World!\";

document.write(txt.length);

</script>

In the Above Java Script we use length property to find out the numbers of characters associated with srting.

Output:12

How to use Special Characters in JavaScript?

 JavaScript provide us facility to add some special characters (like:new line,quotes and some other special character) to a text string. We use this special character after backslash sign. 

Example:

var txt = \"Hello Client,\"thank you for visit\"R4R Welcomes You!\";

document.write(txt); 

We know that in JavaScript we write string inside the double or single quote. That say we sliced string to: Hello client. We used special character \'/\' to solved this problem. We placed \'/\' before each double quote in\"thank you for visit\". 

var txt = \"Hello Client,\"thank you for visit\"R4R Welcomes You!\"; 

document.write(txt); After that we will get our required output.Like that Hello Client,thank you for visit R4R Welcomes You!

I have given you some special characters that we used in JavaScript are:\'single quote\"double quote&ampersand\\backslashnnew linercarriage returnttabbbackspacefform feed

How to use Math Object in JavaScript?

 Using Math Object we can execute the some Mathematical jobs.

I have given you a Syntax using them we can use methods and properties of Mathematics.

var pi_value=Math.PI;

var sqrt_value=Math.sqrt(25);

I have shown you how to use Mathematical Methods.

example:document.write(Math.round(3.8)); 

Output:4

Using random method we can generated random numbers between 0 to 1. 

document.write(Math.random());Output:0.1672748491468966 In this example we use the floor() and random() 

methods of the Math object to return a random number between 0 and 10. 

document.write(Math.floor(Math.random()*11));

 Output:4

How to use Boolean Object in JavaScript?

 Using Boolean Object we can get output in the form of true/false(Boolean Values). 

Syntax used to create Boolean Object are given below:var myBoolean=new Boolean(); 

If the Boolean object has no initial value or if it is 0, -0, null, \"\", false, undefined, or NaN, the object is set to false. Otherwise it is set to true.

Below I have given you code to create Boolean objects with an initial value of false

var myBoolean=new  Boolean();
var myBoolean=new Boolean(0); 
var myBoolean=new Boolean(null); 
var myBoolean=new Boolean(\"\");
var myBoolean=new Boolean(false); 
var myBoolean=new Boolean(NaN);

  1. Below I have given you code to create Boolean objects with an initial value of true.
  2. var myBoolean=new Boolean(true);
  3. var myBoolean=new Boolean(\"true\"); 
  4. var myBoolean=new Boolean(\"false\"); 
  5. var myBoolean=new Boolean(\"vivek\");

How you can perform restriction for user not to copy web page in JavaScript?

 By disable right click on web page we can prevent our web page source code from user. 

Example:

var message=\"Sorry! Right Click is Disabled on this page\"; 

function clickIE4() 

{

 if (event.button==2) 

alert(message);return false;

 }

 }

 function clickNS4(e) 

{

 if (document.layers||document.getElementById&&!document.all) 

if (e.which==2||e.which==3)

{

alert(message);

 return false;

}

 }

How we get value using JavaScript?

 Given below I have write a syntax to get value. Syntax:getElementById(\"\");.

<input type=\"text\" name=\"txtJob\" id=\"txtJob\" value=\"software\">

In this way you will get your value in java scripy code.

var jobValue = document.getElementById(\'txtJob\').value();


How you perform Validation from JavaScript?

 Using JavaScript we can validate the input of the HTML page before sending it into server. I have given you example that shows you how perform on required fields and E-mail. we use this code when we want to validate fields using JavaScript.

Syntax:

function validate_required(field,alerttxt)

{

if (value==null||value==\\\"\\\")

{

alert(alerttxt);

return false;

}

else

{

return true;

}

}


We use that code when we want to perform E-mail validation.

Syntax:

function validate_email(field,alerttxt)

{with (field){apos=value.indexOf(\\\"@\\\");

dotpos=value.lastIndexOf(\\\".\\\");

if (apos<1||dotpos-apos<2)

{

alert(alerttxt); return false;

}

else

{

return true;

}

}

}

how we call function in JavaScript?

I have given you Example which show you how to call function in JavaScript.

Example

<script language=\"javascript\" type=\"text/javascript\">
//Here I Declare Function
function fun()
{
    alert(\"function called\");
}
//Here I call function from the script
fun();
</script>
//call function is called when click on button.
<input type=\"button\" onclick=\"fun()\"/>

How to implement Time Control in JavaScript?

Follwing way we can implement time control function.

setInterval()executes a function, over and over again, at specified time intervals

setTimeout()executes a function, once, after waiting a specified number of milliseconds

Syntax: 

setInterval(function () 

{

alert(\"Hello\"), 3000);

}

output:Alert \"hello\" every 3 second

What is the JavaScript?

 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

How you define JavaScript Code?

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>

Is Java and JavaScript are same or not?

 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?

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?

  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?

 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?

 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:


Hello World!





    

In HTML where JavaScript will executed?

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?

 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?

 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?

 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 Blocks?

 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:

Here you write header

Here write first paragraph

Here write second paragraph

How we use JavaScript Comments?

 
 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.
 

How you define Javascript Variable?

 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 create variable and assign value to those variables in JavaScript?

  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;

How you define JavaScript Operator?

 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 


How you define Comparison and Logical Operators?

  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.

How to use Conditional Statements in JavaScript?

 
Using Conditional statements we can apply different actions on different conditions.
JavaScript provide has four different conditional statements.
1.if statement: This statement is used to execute some specific code when specific condition is true.
Syntax:
if (condition)
{
this code will executed if condition is true
}
Example:
<script type="text/javascript">
//Write a "Good Afternoon" welcome if
//the time is greater than 12
var d=new Date();
var time=d.getHours();
if (time>12) 
{
document.write("<b>Good Afternoon</b>");
}
</script>
2.if...else statement: If condition is true than execute some code else execute different code.   
Syntax:
if (condition)
{
This code will executed if condition is true
}
else
{
This code will executed if condition is not true
}
Example:
<script type="text/javascript">
//If the time is greater than 12,
//you will get a "Good Afternoon" welcome.
//Otherwise you will get a "Good day" welcome.
var d = new Date();
var time = d.getHours();
if (time > 12) 
{
document.write("Good Afternoon");
}
else
{
document.write("Good day");
}
</script>
3.if...else if....else statement: Using this statement we can select one of many blocks of code to be executed. 
Syntax:
if (condition1)
{
This code will executed if condition1 is true
}
else if (condition2)
{
This code will executed if condition2 is true
}
else
{
This code will executed if condition1 and
condition2 are not true
}
Example:
<script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time<10)
{
document.write("<b>Good morning</b>");
}
else if (time>10 && time<16)
{
document.write("<b>Good Afternoon</b>");
}
else
{
document.write("<b>R4R Welcomes You!</b>");
}
</script>
4.switch statement: Using this statement we can select one of many blocks of code to be executed. 
Syntax;
switch(i)
{
case 1:
  execute code block 1
  break;    
case 2:
  execute code block 2
  break;
default:
  code to be executed if n is
  different from case 1 and 2
}
Example:
<script type="text/javascript">
//You will receive a different greeting based
//on what day it is. Note that Sunday=0,
//Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6.

var d=new Date();
theDay=d.getDay();
switch (theDay)
{
case 0:
  document.write("It is Sunday");
  break;
case 1:
  document.write("It is Monday");
  break;
case 2:
  document.write("It is Tuesday");
  break;
case 3:
  document.write("It is Wednesday");
  break;
case 4:
  document.write("It is Thursday");
  break;
case 5:
  document.write("It is Friday");
  break;
case 6:
  document.write("It is Saturday");
  break;
default:
  document.write("Press only numbers from 0 to 6 ");
}
</script>
 

How you define Popup Boxes in JavaScript?

 In JavaScript we only can make three type of Popup Boxes.

These are Alert Box,Confirm box and Prompt Box.

 Alert Box: We use Alert boxe in that case where want check the information those given by user.When Alert box                      popup comes user should press \'ok\' to execute this page.Syntax:alert(\"anytext\"); 

 Confirm Box: Use this box we want to verfy or accept something from user.Syntax:confirm(\"anytext\"); 

 Prompt Box: Use when we want user to input a value before entering a page. When Alert box popup comes user                      should press \'ok\' to proceed than after entering an input value.syntax:(\"anytext\",\"defaultvalue\")                       

 

How we use functions in JavaScript?

 
Functions is executed by the event or whenwe called.Functions are reusable block of code.
 If we want that the browser from executing a script when the page loads,Than we have to  write our script into a function.
 We can execute the function code by using an event or simply called the function.We can call from any where of the page.If you want to call the function from different page than you have embedded function with in external JavaScript.
 We can defined as function in both <head> and <body>.
Example:
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello User!");
}
</script>
</head>
<body>
<form><input type="hidden" name="phpMyAdmin" value="f43d4e0b88acea2d2a393515f6bf38f2" /><input type="hidden" name="phpMyAdmin" value="70ac9566533a2665b6597346aab7f985" />
<input type="button" value="Click me!"
onclick="displaymessage()" >
</form>
</body>
</html>
 

How to define function in JavaScript?

 We function in JavaScript like that,
Syntax:
function functionname(var1,var2,...,varz)
{
Write some code here
}
 Using var1, var2,..varz variables or values passed into the function.Where as { and } show that the start and end of function.

What is the Lifetime of JavaScript variables?

 Lifetime of JavaScript variables is total time when variable is created till this variable will destroy. 

 When we declare any varaible inside the function than variable Lifetime will start when it declare and end with when this function will executed. Means that when function is exit than variable declare on this function will destroyed.We called this type of variable local variable.

 we can use same local variable with different function.may be same local variable have different values in different functions.because this variables are declared in function than the will destroy when function will executed. If you want that all function will use the same variablename with same value.Than we can declare this variables outside the functions. Lifetime of this type of variable is started when they are created and destroy when page will will closed.

How we use Loop in JavaScript?


 
Using Loop we can execute same block of code into a specific number of times.
 JavaScript support two ypes of Loops:
1.for
2.while

1.for: We use for loop to execute a block of code for specfic number of times.
Syntax:
for (variable=startvalue;variable<=endvalue;variable=variable+increment) 
{
    code executed
}
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
document.write("Number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
Output:
Number is 0
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
2.while: This loop execute block of code when specifc condition is true.
Syntax:
while (variable<=endvalue)
{
    code executed
}
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("Number is " + i);
document.write("<br />");
i=i+1;
}
</script>
</body>
</html>
Output:
Number is 0
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
3.do..while: In do..while Loop executed atleast one time after that it check the condition if it true than execution proceed otherwise loop stopped the execution.
Syntax:
do
{
    code executed
}
while (variable<=endvalue);
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
do 
{
document.write("Number is " + i);
document.write("<br />");
i=i+1;
}
while (i<0);
</script>
</body>
</html>
Output:
Number is 0
 

How we use Break and Continue Statement in JavaScript?


 
 Break and Continue are Special Statement which we used inside the JavaScript.
1.Break: If we write break statement inside the loop than it will break that loop and continue execution of code(if any) that we write after this loop.
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
if (i==2)
{
break;
}
document.write("Number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
Output:
Number is 0
Number is 1

2.Continue: If we use continue statement than it will break the current loop and continue with the next value.
Example:
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=5;i++)
{
if (i==2)
{
continue;
}
document.write("Number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
Output:
Number is 0
Number is 1
Number is 3
Number is 4
Number is 5
 

How you define for..in statement in JavaScript?

How you define Events in JavaScript?

 We can say that Events are actions those are detected by JavaScript.Using event we can trigger the JavaScript 


functions.I have given you some example of events that are given below:


1.A keystroke 

2.To submit an HTML form 

3.To select an input box of HTML form4.A mouse click 

5.When web page or image loading Generally we attach an event with specific functions.We execute that functions    when this event occurs.

How you use try..catch statement in JavaScrpt?

 We can check the error from web pages by only two ways.

These are: 

1.try..catch 

2.onerror try..catch: Using try..catch we can check the errors from a block of code. In this try block have a code that want to run and the catch block have a code to be executed if any error comes.

 Syntax:try{//code want to execute}catch(err){//if error comes than this code will handle} 

   Since alert() is misspelled than JavaScript error comes.This time, the catch block catches the error and executes a code to handle this error.Than displays a error message.

How to use String Object in JavaScript?

 Using Script Object we can to stored text.
Example:
Here, I used the String Object to find out the length of the string.
var txt="Hello world!";
document.write(txt.length);
Output:
12

How to use Date Object in JavaScript?

 Using Date() Object we can create date object. 

Example:var myDate=new Date();myDate.setFullYear(2009,0,3);

 Here, I set the Date object to the specific date(3rd feb 2009) I have given you a example where I compare two 

dates. This program gives output if date is 3rd feb 2009 as Today is your birthday.var myDate=new Date();

myDate.setFullYear(2009,0,3);var today = new Date();if (myDate=today){alert(\"Today is your birthday\");} 

elseif(myDate)

How to use Array Object in JavaScript?

 Using array Object we can store multiple values into a single variable. 

We create an Array Object using that syntax.var myCars=new Array(); Now, I will show you how to insert values into a Array variable. 

var myfriendsnames=new Array();myfriendsnames[0]=\"Abhi\";myfriendsnames[1]=\"Sud\"; 

myfriendsnames[2]=\"Tonu\"; \'OR\' var myfriendsnames=new Array(\"Abhi\",\"Sud\",\"Tonu\"); If you want to show that

the perticular value of an array object.Than,document.write(myfriendsnames[1]);

 Output:Sud

 We can also modify the perticular value of an Array Object.myfriendsnames[1]=\"Harry\"; Than we want to print 

 value at index 1 will be:document.write(myfriendsnames[1]);

 Output:Harry

How you use RegExp Object in JavaScript?

 RegExp is stands for regular expression.Using RegExp Object we can perform some specific search in text. We use them when we want search for some specific Pattern in text. Suppose if want to search a single character from given pattern than write code like that:var pattern=new RegExp(\"[abc]\"); Find any character between the brackets.

RegExp Object has 3 methods: 

  1. test() 
  2. exec()
  3. compile().
Using test() we can search a specific value from the string.Return result in terms of true or false.

Using exec() we can search a specific value from the string.Return value if it found the value otherwise it returns null if does not find the searched value.

Using compile() we can change the RegExp.

How to use test(),exec() and compile() methods of RegExp Object?

 Regexp Object provde us three methods.

These are:

  1. test()
  2. exec()  
  3. compile() 

test() :When we want to search a specific value from a string,It gives output in the forms of True or False.

Example:

var pattern=new RegExp(\"t\");

document.write(pattern.test(\"It will never be wasted\")); 

Output: true 

exec():It is also used to search a value from a string but it generate different result. like: If vlue is matched return value otherwise I will return NULL(means value does not matched). 

Example:

var pattern=new RegExp(\"t\");document.write(pattern.exec(\"Always try to improve\")); 

Output:t

compile() : Using compile() method we can change both the search pattern and add or remove the second parameter.Example:var pattern=new RegExp(\"t\");document.write(pattern.test(\"Always try to improve \"));pattern.compile(\"z\");document.write(pattern.test(\"Always try to improve\"));0utput :truefalse Reason of this output is that first it check for pattern \'t\' because it is in our text.So,it will return true and than search for \'z\'.Because it is not in our text than it will return false.

What is the main difference b/w Client Side JavaScript and Server Side JavaScript?

 Client Side JavaScript is that in this we can use the core language plus extras such as the predefined objects, only relevant to running Javasript in a browser. Client Side JavaScript is embedded directly in the HTML pages and is interpreted by the browser completely at the run time.

Server Side JavaScript is that in this we can use the core language plus extras as the predefined objects and functions only relevant to running Javasript in a server. Server Side JavaScripts are compiled before they are deployed.

How to add Dynamic combo box at runtime in JavaScript?

We can add Dyanmic combo box at runtime by using that code. 

Example:

 for (var i=0;i<7;i++)

 {

      document.forms[0].cmb1.options[i]= new Option(\"Test\"+i,i);

 }

JavaScript is case-sensitive or not?

 JavaScript is an case-sensitive scripting language.

What is JavaScript?

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?

 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?

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.

Where are cookies actually stored on the hard disk?

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

What can javascript programs do?

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 to set a HTML document's background color?

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

What is reason of the "Access is Denied" ?

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?

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.

Are Java and JavaScript the Same?

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?

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?

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?

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

What is a prompt box?

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

Can javascript code be broken in different lines?

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?

Use the below specified style of comments







			

How you define Popup Boxes in JavaScript?