Professional Documents
Culture Documents
JavaScript contains a standard library of objects, such as Array, Date, and Math,
and a core set of language elements such as operators, control structures,
and statements. Core JavaScript can be extended for a variety of purposes by
supplementing it with additional objects; for example:
Client-side JavaScript extends the core language by supplying objects to
control a browser and its Document Object Model (DOM). For example, client-
side extensions allow an application to place elements on an HTML form and
respond to user events such as mouse clicks, form input, and page
navigation.
Server-side JavaScript extends the core language by supplying objects
relevant to running JavaScript on a server. For example, server-side
extensions allow an application to communicate with a database, provide
continuity of information from one invocation to another of the application, or
perform file manipulations on a server.
Advantages
Less server interaction − You can validate user input before sending the page
off to the server. This saves server traffic, which means less load on your server.
Immediate feedback to the visitors − They don't have to wait for a page
reload to see if they have forgotten to enter something.
Increased interactivity − You can create interfaces that react when the user
hovers over them with a mouse or activates them via the keyboard.
Richer interfaces − You can use JavaScript to include such items as drag-and-
drop components and sliders to give a Rich Interface to your site visitors.
Syntax
<script ...>
JavaScript code
</script>
<script type="text/javascript">
<!--
function functionname(parameter-list)
statements
//-->
</script>
Eg.
<script type="text/javascript">
<!--
function sayHello()
alert("Hello there");
}
//-->
</script>