Chapter 00

JavaScript Introduction

JavaScript is a programming language used to make websites interactive, dynamic, and responsive to user actions.

What is JavaScript Introduction?

  • JavaScript is one of the most popular programming languages for web development.
  • HTML creates the structure of a webpage, CSS controls its design, and JavaScript adds behavior and interaction.
  • JavaScript can run directly in a web browser.
  • JavaScript is used for forms, buttons, menus, sliders, calculators, games, APIs, and web applications.

Syntax

let message = 'Hello AIFA';
console.log(message);

Example

Try understanding this code before running it.
<!DOCTYPE html>
<html>
<body>
<h2>AIFA Coding Lab</h2>
<button onclick="showMessage()">Click Me</button>

<script>
function showMessage() {
    alert('Welcome to JavaScript!');
}
</script>
</body>
</html>

Important Points

  • JavaScript can be written inside the <script> tag in an HTML page.
  • Using semicolons at the end of statements is a good coding practice.
  • JavaScript is case-sensitive.
  • The browser Developer Console is useful for checking output and errors.

Common Mistakes

  • Confusing JavaScript with Java. They are different programming languages.
  • Ignoring uppercase and lowercase differences.
  • Closing the <script> tag incorrectly.

Real-World Use

Login forms, shopping websites, online calculators, dashboards, animations, games, and modern web applications use JavaScript.

Practice Exercise

Practice: First JavaScript Program
Create an HTML page with a button. When the button is clicked, display 'Welcome to AIFA' in an alert box.

Ready to write code?

Open the JavaScript editor and run your code with live output.

Try It Yourself →