Introduction to JavaScript (JS)
JavaScript Programming for Beginners
What is JavaScript?
JavaScript (JS) is a high-level, interpreted programming language used to make web pages interactive. While HTML builds the structure and CSS adds the style, JavaScript acts as the brain of the website.
JavaScript was created in just 10 days by Brendan Eich in 1995. It is now the most used language for web development!
JavaScript Syntax Basics
Variables (Storing Data)
In modern JavaScript, we use let and const to store information:
let: For values that can change (e.g.,let score = 0;)const: For values that stay the same (e.g.,const birthYear = 2008;)
Case Sensitivity: JavaScript is case-sensitive. This means
MyScore and myscore are two different variables.
JavaScript Data Types
| Type | Example | Description |
|---|---|---|
| String | "Hello" | Text wrapped in quotes |
| Number | 42 / 3.14 | Whole or decimal numbers |
| Boolean | true / false | Logical "Yes" or "No" |
| Array | [1, 2, 3] | A list of items |
Operators & Equality
In JS, checking for equality is slightly different than in math:
===(Strict Equality): Checks if the value and the type are the same. (Recommended)==(Loose Equality): Checks only the value.
5 == "5" // true
5 === "5" // false (One is a Number, one is a String)
Simple Interactive Project
Try this Prompt Calculator by pasting it into your browser's console (F12):
let name = prompt("What is your name?");
let num1 = parseFloat(prompt("Enter first number:"));
let num2 = parseFloat(prompt("Enter second number:"));
alert("Hello " + name + "! The sum is: " + (num1 + num2));
๐ Test Your Knowledge
Select the correct answer for each question and click 'Submit' to see your score.
Comments
Post a Comment