JavaScript Full Notes
1. What is JavaScript?
JavaScript is a lightweight, interpreted programming language mainly used to make web
pages interactive. It runs on the client side (browser) and adds dynamic behavior like
animations, form validations, and pop-ups.
2. Features of JavaScript
- Lightweight and fast
- Interpreted language
- Dynamic typing
- Object-based
- Event-driven
- Cross-platform
- Easy to integrate with HTML/CSS
3. Advantages of JavaScript
- Runs on the client-side
- Reduces server load
- Adds interactivity to web pages
- Easy to learn
- Supported by all browsers
- Works well with HTML/CSS
4. Disadvantages of JavaScript
- Code is visible to users (security risk)
- Behavior may vary across browsers
- Can be disabled by users
- Limited file handling capability
- Not suitable for heavy backend tasks alone
5. What is a Script?
A script is a set of instructions written to perform a specific task. In web development, it
often refers to code written in a scripting language like JavaScript.
6. Types of Script
- Client-side Script: Runs in the browser (e.g., JavaScript)
- Server-side Script: Runs on the server (e.g., PHP, Python)
7. How JavaScript Works
1. Browser loads HTML page.
2. Finds JavaScript code inside <script> tags or linked .js files.
3. JavaScript engine interprets and executes the code.
4. Executes code and manipulates the web page as needed.
8. Ways to Execute JavaScript
a) Inline: <button onclick="alert('Hello!')">Click me</button>
b) Internal: <script>alert("Internal JS");</script>
c) External: <script src="script.js"></script>
9. JavaScript Coding Rules
- Use camelCase for variables
- End statements with a semicolon (;)
- Use comments: // single-line or /* multi-line */
- Avoid global variables
- Indent code properly
10. Ways to Display Output
- alert(): Popup box
- document.write(): Writes to page
- console.log(): Outputs to browser console
- innerHTML: Changes content of HTML elements
11. Variables in JavaScript
Variables are containers for data.
var x = 5;
let y = "Hello";
const PI = 3.14;
Types:
- var: Function-scoped
- let: Block-scoped
- const: Block-scoped, constant
12. Ways to Use JavaScript in Web Page
a) Inside <script> tag: <script>alert("JS");</script>
b) External file: <script src="main.js"></script>
13. Operators in JavaScript
Arithmetic: +, -, *, /, %, ++, --
Assignment: =, +=, -=, etc.
Comparison: ==, !=, ===, <, >, etc.
Logical: &&, ||, !
Bitwise: &, |, ^, ~, <<, >>, >>>
Special: typeof, instanceof, new, delete
14. Control Statements
if, if-else, else-if ladder, switch-case
Loops:
- for
- while
- do...while
- for...in (objects)
- for...of (arrays)