Introduction to JavaScript (JS)

JavaScript Programming for Beginners - cmpnoteblog

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

TypeExampleDescription
String"Hello"Text wrapped in quotes
Number42 / 3.14Whole or decimal numbers
Booleantrue / falseLogical "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.

1. Which tag is used to insert JavaScript into an HTML document?

2. Which keyword is best for a variable that will never change?

3. What is the correct way to write "Hello World" in an alert box?

4. Which operator is used for "Strict Equality"?

5. How do you start a single-line comment in JS?

Comments

Popular posts from this blog

Complete Computer Studies/ICT Curriculum for JSS 1 to SSS 3

90 Objective Examination Questions in Major Subjects

JSS 3 Objective Questions and Answers in Computer studies