JavaScript Introduction

 

JavaScript (JS) is a versatile, high-level programming language primarily used to make web pages interactive and dynamic.

 

Advantages
  • High Speed
  • Reduced Server Load
  • Rich Interactivity
  • Versatility
  • Massive Community
  • Simplicity
 
Disadvantages
  • Security Issues
  • Browser Inconsistency
  • Single Threaded
  • Debugging Challenges

Features of JavaScript

  • It is a client-side scripting language that runs inside the browser.
  • It is interpreted, so no separate compilation is needed.
  • It is case-sensitive.
  • It is event-driven: code can run when a user clicks, types or loads a page.
  • It works on all modern browsers and operating systems.

Adding JavaScript to a Web Page

JavaScript code is written inside the <script> tag, either in the <head> or the <body>:

<script>
  document.write("Hello World");
  alert("Welcome!");
</script>

It can also be kept in a separate file and linked: <script src=”app.js”></script>.

Uses of JavaScript

  • Form validation, e.g. checking that an email field is not empty.
  • Showing pop-up messages using alert(), confirm() and prompt().
  • Creating image sliders, menus and animations.
  • Changing page content without reloading.

Note

JavaScript and Java are different languages. JavaScript was created by Brendan Eich at Netscape in 1995.

Important Questions

Q. What is JavaScript?
Ans. JavaScript is a client-side, interpreted scripting language used to make web pages interactive.

Q. Which tag is used to insert JavaScript into HTML?
Ans. The <script> tag.

Q. Write the output of: document.write(5 + 3);
Ans. 8