TutorialsJSJavaScript Introduction
Share:

JavaScript Introduction

beginner

Part of JavaScript Fundamentals

Theory

JavaScript is a high-level, interpreted programming language that is one of the core technologies of the World Wide Web. Created by Brendan Eich in 1995, JavaScript has evolved from a simple scripting language into a powerful, multi-paradigm language used for both client-side and server-side development.

The language has undergone significant evolution. ES5 (ECMAScript 2009) added strict mode, JSON support, and array methods like forEach and map. ES6 (ECMAScript 2015) was a major milestone, introducing let/const, arrow functions, classes, template literals, destructuring, and modules. Modern JavaScript (ES2016+) continues to add features like async/await, optional chaining, and nullish coalescing.

JavaScript runs in multiple environments. In the browser, it manipulates the DOM and handles user interactions. On the server, Node.js allows JavaScript to handle file systems, databases, and networking. JavaScript is also used in mobile apps (React Native), desktop apps (Electron), and IoT devices.

Statements are individual instructions executed by the browser. Semicolons are optional in JavaScript due to automatic semicolon insertion (ASI), but using them is a good practice. JavaScript is case-sensitivemyVariable and myvariable are different identifiers.

// This is a single-line comment
/* This is a multi-line comment */

Strict mode ("use strict") catches common errors and prevents the use of potentially problematic features. Place it at the top of a script or function.

The <script> tag can be placed in the <head> or <body> of an HTML page. Modern practice places scripts just before the closing </body> tag or uses the defer attribute for better page load performance.

Practical Examples

Example 1: Your First JavaScript Program
javascript
Example 2: Basic Syntax and Statements
javascript

Exercises

Print Your Information

easy

Write JavaScript code that prints your name, age, and favorite programming language using console.log(). Use at least three separate console.log() statements.

Starter Code:

// Print your name, age, and favorite language below

Expected Output:

John Doe\n25\nJavaScript

Fix the Syntax Errors

easy

The following code contains multiple syntax errors. Rewrite it correctly: console.log('Hello)(; let 1stName = 'John'; console.log(firstname)

Starter Code:

// Fix the code below

Expected Output:

Hello John

Write an HTML Page with JavaScript

medium

Write a complete HTML page that includes JavaScript in the <head> using a <script> tag. The script should print 'Page Loaded Successfully' to the console.

Starter Code:

<!-- Write your HTML here -->

Expected Output:

Page Loaded Successfully

Mini Quiz

Mini Quiz

Mini Project

Mini Project: Personal Introduction Script

Create a JavaScript program that stores personal details in variables and prints a formatted introduction paragraph to the console.

Requirements:

    Bonus Challenge

    Add an expression that calculates your birth year based on your age and prints it.