JavaScript Introduction

Lesson 1 of 40 7 min read Intermediate

What is JavaScript?

JavaScript is a high-level, interpreted programming language that is one of the core technologies of the World Wide Web. It enables interactive web pages and is an essential part of web applications.

Fun Fact!

JavaScript was created in just 10 days by Brendan Eich in 1995 while he was working at Netscape.

JavaScript Features:

  • Dynamic and interpreted language
  • Client-side and server-side programming
  • Event-driven programming
  • Object-oriented programming support
  • Cross-platform compatibility

Your First JavaScript Code

Let's start with the classic "Hello, World!" example:

JavaScript
// This is a comment
console.log("Hello, World!");

// You can also use alert
alert("Welcome to JavaScript!");

Code Explanation:

  • console.log() - Prints output to the browser console
  • alert() - Shows a popup dialog box
  • // - Single-line comment
  • Semicolons (;) are used to end statements

Where to Write JavaScript

JavaScript can be included in HTML documents in several ways:

1. Inline JavaScript

HTML
<button onclick="alert('Button clicked!')">Click Me</button>

2. Internal JavaScript

HTML
<script>
    function greetUser() {
        alert("Hello from JavaScript!");
    }
</script>

3. External JavaScript

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

Interactive JavaScript Console

Try JavaScript code in real-time:

Click "Run Code" to see output here...

Quick Challenge

Try this: Create a variable called 'age' and assign it your age, then display it using console.log()