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&ersand\\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); - Below I have given you code to create Boolean objects with an initial value of true.
- var myBoolean=new Boolean(true);
- var myBoolean=new Boolean(\"true\");
- var myBoolean=new Boolean(\"false\");
- 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. - JavaScript is a trademark of Sun Microsystem.
- It is dynamic,Weak and prototype language.
- Using JavaScript we can make our HTML pages interactive.
- JavaScript is a scripting language.
- We can embedded JavaScript directly into HTML pages.
- 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: - <script type=\"text/javascript\">
- document.write(\"<h1>Here you write header</h1>\");
- document.write(\"<p>Here write your first paragraph</p>\");
- document.write(\"<p>Here write your second paragraph</p>\");
- </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- JavaScripts are simple pre compiled code.We use this code into the HTML pages to make interactive .It is easy to use.
- Using JavaScript we can set dynamic text into the HTML page.Example:document.write(\"+text+\")
- we can also set JavaSCript perform when some event happen means its automatically call when some special event execute.
- Using JavaScript we can read HTML element and changed the content of element.
- Using JavaScript we can validate the data before sending to to the server.Means that we can reduce the server Urocessing before using JavaScript.
- Using JavaScript we can identify the user\'s browser.
- 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?
|
- ECMAScript is an official name of JavaScript.
- ECMA Organization developed and maintain ECMAScript.
- 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.
- It gets cettificated by international ISO (ISO/IEC 16262) standard in 1998.
- 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
|