summarized-cs
summarized-cs
1. JavaScript Basics
● JavaScript is a client-side scripting language that adds interactivity to web pages.
● It is loosely typed (variables don’t require explicit data types).
● Can be embedded in HTML using:
○ Internal (<script>...</script>)
○ External (<script src="file.js"></script>)
○ Inline (onclick="function()") (not recommended)
Data Types
Type Description Example
String Operations
Method Description Example Output
Number Operations
Operator Description Example
+ Addition 5 + 3 →
8
- Subtraction 10 - 4 →
6
* Multiplication 2 * 3 →
6
/ Division 10 / 2 →
5
Special Numbers: NaN (Not a Number), Infinity, -Infinity
3. JavaScript Operators
Arithmetic Operators
Comparison Operators
Operator Meaning Example Output (a = 10, b =
5)
== Equal to a == 10 → true
Logical Operators
Operator Description Example Output
` ` (OR)
Assignment Operators
Operator Meaning Example
= Assign value x = 5
+= Add & assign x += 3 (same as x = x
+ 3)
4. JavaScript Functions
● Functions allow reusable code blocks.
● A function must be declared before being called.
Function Syntax
function greet(name) {
return "Hello, " + name + "!";
}
console.log(greet("Pisay")); // Output: "Hello, Pisay!"
Switch Statement
let grade = 75;
switch (true) {
case (grade < 60): console.log("F"); break;
case (grade < 70): console.log("D"); break;
case (grade < 80): console.log("C"); break;
default: console.log("B or A");
}
Date Object