JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.
Some of the features of JavaScript are:
Some of the disadvantages of JavaScript are:
The function which has named at the time of definition is called a named function. For example
function msg()
{
document.write("Named Function");
}
msg();
Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue. In other words, you can say JScript is the same as JavaScript, but Microsoft provides it.
A simple example of JavaScript hello world is given below. You need to place it inside the body tag of HTML.
<script type="text/javascript">
document.write("JavaScript Hello World!");
</script>
I am assuming that js file name is message.js, place the following script tag inside the head tag.
<script type="text/javascript" src="message.js"></script>
// for Single line comments and
/* Multi
Line
Comment
*/
Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.
The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled. The clearInterval(id) function instructs the timer to stop.
Timers are operated within a single thread, and thus events might queue up, waiting to be executed.
"==" checks only for equality in value whereas "===" is a stricter equality test and returns false if either the value or the type of the two variables are different.
An alert box displays only one button which is the OK button.
But a Confirmation box displays two buttons namely OK and cancel.
There are three types of errors: