LetUsLearn JavaScript Tutorial

JavaScript is used to create client-side dynamic pages.

JavaScript is an object-based scripting language which is lightweight and cross-platform.

JavaScript is not a compiled language, but it is a translated language. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.

Application of JavaScript

JavaScript is used to create interactive websites. It is mainly used for:

  • Client-side validation,
  • Dynamic drop-down menus,
  • Displaying date and time,
  • Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog box),
  • Displaying clocks etc.

JavaScript Example


<h2>Welcome to JavaScript</h2>  


document.write(“Hello JavaScript by JavaScript”);  


In the above exapmle

The script tag specifies that we are using JavaScript.

The text/javascript is the content type that provides information to the browser about the data.

The document.write() function is used to display dynamic content through JavaScript. We will learn about document object in detail later.

HTML/DOM events for JavaScript

JavaScript code is executed with HTML/DOM events and they are widely used in JavaScript code. So before learning JavaScript, let’s have some idea about events.

onclickoccurs when element is clicked.
ondblclickoccurs when element is double-clicked.
onfocusoccurs when an element gets focus such as button, input, textarea etc.
onbluroccurs when form looses the focus from an element.
onsubmitoccurs when form is submitted.
onmouseoveroccurs when mouse is moved over an element.
onmouseoutoccurs when mouse is moved out from an element (after moved over).
onmousedownoccurs when mouse button is pressed over an element.
onmouseupoccurs when mouse is released from an element (after mouse is pressed).
onloadoccurs when document, object or frameset is loaded.
onunloadoccurs when body or frameset is unloaded.
onscrolloccurs when document is scrolled.
onresizedoccurs when document is resized.
onresetoccurs when form is reset.
onkeydownoccurs when key is being pressed.
onkeypressoccurs when user presses the key.
onkeyupoccurs when key is released.

3 Places to put JavaScript code