Java script Chapter 1

🔹 1. What is JavaScript?

  • JavaScript (JS) is a scripting language used to make web pages interactive and dynamic.
  • It runs in the browser (client-side).
  • Developed by Brendan Eich in 1995.

🔹 2. Features of JavaScript

  • Lightweight & Easy to learn
  • Interpreted (no need for compilation)
  • Event-driven & Object-based
  • Platform independent
  • Can manipulate HTML & CSS dynamically

🔹 3. Uses of JavaScript

  • Validating forms (e.g., checking empty fields)
  • Creating animations, sliders, and popups
  • Building interactive web applications
  • Handling user events (click, mouseover, etc.)

🔹 4. How to Add JavaScript to a Web Page

There are three ways:

A. Inline Script

<button onclick="alert('Hello!')">Click Me</button>

B. Internal Script

<script>
  alert("Welcome to my site!");
</script>

C. External Script

<script src="script.js"></script>

🔹 5. Output Methods

  • alert("message") – shows popup message
  • console.log("message") – prints in console
  • document.write("text") – writes on web page
  • innerHTML – changes HTML content dynamically

🔹 6. Comments

// Single-line comment
/* Multi-line comment */

Leave a Comment

Your email address will not be published. Required fields are marked *