Javascript Example

tutorial and example
tutorial and example

Try Now

JavaScript can be implemented using JavaScript statements that are placed within the <script>…</script>.

Try Now

JavaScript code can be written in 3 places in JavaScript

  1. Between the <body>……</body> tag of HTML.
  2. Between the <head>……</head> tag of HTML.
  3. In .jsfile(external JavaScript).

Example (code between the body tags)

The below example displays JavaScript code in body tag.

Try Now

Example2 (code between the head tag)

In below example we are creating function msg(). To create a function in JavaScript need to write function in function_name. To call function we need to work on event. Here, we are using one click event to call msg() function.

Try Now

External JavaScript file

We can create external JavaScript file and include it into HTML files.

It provides code reusability because single JavaScript file can be used in several HTML pages.

It increases the speed of the web page.

File must be saved in .js extension.

Example

Try Now