Copy-of-Programming-for-the-Web
Copy-of-Programming-for-the-Web
by Nafeesath Shamooda
Introduction to JavaScript
A Client-Side Language Key Functions
JavaScript is a scripting language that adds JavaScript enables tasks like handling user input,
interactivity and dynamic behavior to web pages. manipulating website elements, and creating engaging
user experiences.
Data Types and Variables
Number String
Represents numerical data, Represents text data,
e.g., 10, 3.14, -5. enclosed in quotes, e.g.,
"Hello," "World."
Boolean
Represents true or false values, e.g., true, false.
Arithmetic Operators
Addition Subtraction
Adds two numbers together, Subtracts one number from
e.g., 5 + 3 = 8. another, e.g., 10 - 4 = 6.
Multiplication Division
Multiplies two numbers Divides one number by another,
together, e.g., 2 * 6 = 12. e.g., 15 / 3 = 5.
Comparative Operators
1 Equals
Checks if two values are equal, e.g., 5 == 5 (true).
2 Not Equals
Checks if two values are not equal, e.g., 5 != 6 (true).
3 Greater Than
Checks if one value is greater than another, e.g., 10 > 5 (true).
4 Less Than
Checks if one value is less than another, e.g., 3 < 8 (true).
String Manipulation
Concatenation
Combines two or more strings, e.g., "Hello" + " " + "World" =
"Hello World".
Length
Determines the length of a string, e.g., "Hello".length = 5.
Substring
Extracts a portion of a string, e.g., "Hello".substring(1, 3) = "el".
Replace
Replaces specific characters within a string, e.g.,
"Hello".replace("H", "h") = "hello".
Arrays and Conditional Statements
Arrays
1 Ordered collections of data, e.g., ["apple", "banana", "cherry"].
Conditional Statements
2
If, if..else,else if, switch
Loops
3 Repeat a block of code multiple times, for loop, while
loop and do..whileloope.g., for (i = 0; i < 5; i++)
HTML Forms and Control Events
Input Fields
1
Allow users to enter data, e.g., text boxes, checkboxes, radio buttons.
Control Events
2
Respond to user actions, such as clicking buttons or selecting options.
Form Submission
3 Sends form data to a server for processing, e.g.,
saving information or making requests.
Pop-up Boxes and Conclusion
1 2
Alert Boxes Confirm Boxes
Display messages to the user, e.g., Ask the user for confirmation, e.g.,
alert("Welcome!"); confirm("Are you sure?");
3
Prompt Boxes
Request user input, e.g.,
prompt("Enter your name:");