Are you

What is JavaScript?


JavaScript is used to create client-side dynamic pages. JavaScript is easy to learn. JavaScript is an object-based scripting language which is lightweight and cross-platform.

JavaScript (js) is a lightweight object-oriented programming language that is used to script webpages on many websites. When used with an HTML document, it is an interpreted, complete programming language that enables dynamic interactivity on websites. It was first released in 1995 to allow users of the Netscape Navigator browser to add programs to webpages. Since then, every other graphical web browser has integrated it. Users can create interactive modern web applications with JavaScript without continually refreshing the page. The conventional website makes use of js to offer various forms of simplicity and interactivity.

However, JavaScript has no connection with the Java programming language. The name was suggested and offered during a period when Java was gaining market appeal. Aside from web browsers, databases such as CouchDB and MongoDB employ JavaScript as its scripting and query language.

Features of JavaScript

The following are characteristics of JavaScript:

  • Due to its built-in execution environments, JavaScript is supported by all widely used web browsers.
  • It is a light-weight and interpreted language.
  • The language is case-sensitive.
  • JavaScript adheres to the C programming language's syntax and organization. Thus, it is a structured programming language.
  • Many operating systems, including Windows, macOS, and others, can run JavaScript.
  • It gives consumers excellent control over web browsers.
  • JavaScript is a language with weak typing, where some types are cast implicitly (depending on the operation).
  • Prototypes are used as inheritance in JavaScript, an object-oriented programming language, rather than classes.

Application of JavaScript

JavaScript is used to develop interactive websites. Its major uses are:

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

JavaScript Example 1

<!DOCTYPE>
<html>
<body>
<h1> Welcome to JavaScript</h1>
<script> document.write("Hello JavaScript by JavaScript");</script>
</body>
</html>

Output

JavaScript Example - JavaScript language

JavaScript Example 2

When you look at the paragraph tag with the id demo, you will notice that there is no content in between and that the content is generated when the button is clicked.

One of many JavaScript HTML methods is getElementById().

The example below "finds" an HTML element (with id="demo"), and changes the element content (innerHTML) to Date and Time:

<!DOCTYPE>
<html>
<body>
<h1> My First JavaScript</h1>
<button type="button" onclick="document.getElementById('demo').innerHTML = Date()"> document.write("Click me to display Date and Time.");</button>
<p id="demo"> </p>
</body>
</html>

Output 1: Before click

JavaScript Example

Output 2: After click

JavaScript Example - Learn JavaScript
Next

Courses