JavaScript (JS) - Complete Exam Oriented Notes
1. JavaScript Kya Hai?
- Client-side scripting language
- Adds behavior to web pages (button clicks, form validation, dynamic content)
- HTML = structure, CSS = styling, JS = behavior
2. Variables
- var, let, const
- Example: var x = 5; let y = 10; const z = 15;
3. Data Types
- Number, String, Boolean, Object, Array
4. Operators
- Arithmetic: +, -, *, /
- Assignment: =, +=, -=
- Comparison: ==, ===, !=
- Logical: &&, ||, !
5. Functions
- Block of code called repeatedly
- Example: function greet(name){ alert("Hello " + name); }
6. Events
- onclick, onmouseover, onsubmit, onkeypress
- Detect user actions on web page
7. DOM Manipulation
- [Link]("id").innerHTML = "content";
- Modify HTML dynamically
8. Arrays
- Example: let arr = [1,2,3]; [Link](4); [Link]();
9. Loops
- for, while, do-while
- Example: for(let i=0; i<5; i++){ [Link](i); }
10. Conditional Statements
- if, else, else if
- Example: if(age>=18){ [Link]("Adult"); } else { [Link]("Minor"); }
11. Comments
- Single line: // Comment
- Multi-line: /* Comment */
12. Important JS Methods
- alert(): show message box
- [Link](): print in console
- parseInt() / parseFloat(): convert string to number
- [Link](): JSON to JS object
- [Link](): JS object to JSON string
- pop(): remove last array element
- push(): add element at end
- typeof: check type of variable
Quick Exam Notes:
- JS = behavior, interactive pages
- Web Trinity: HTML + CSS + JS
- ID selector = #id, Class selector = .class
- Comments: // or /* */
- alert(), [Link](), onclick = frequently asked in exam