Internet - Concepts and Overview
Introduction to Scripting Language
A scripting language is a programming language used to write scripts that automate tasks. JavaScript is a
popular scripting language used mainly for web development to create interactive and dynamic web pages.
JavaScript is executed in the browser, allowing developers to control HTML content, validate forms, and
create animations.
Internet - Concepts and Overview
Client Side vs Server Side Scripting
**Client-Side Scripting**:
- Executed in the user's browser.
- Example: JavaScript, HTML, CSS.
- Used for form validation, dynamic content updates, UI interaction.
**Server-Side Scripting**:
- Executed on the web server.
- Example: PHP, Python, Node.js.
- Used for database access, authentication, file handling.
Internet - Concepts and Overview
Advantages of JavaScript
- Fast and efficient on the client-side.
- Reduces server load.
- Easy to learn and implement.
- Enhances user experience with interactivity.
- Widely supported across browsers.
Internet - Concepts and Overview
Features of JavaScript
- Interpreted language (no compilation needed).
- Lightweight and dynamic.
- Event-driven and interactive.
- Object-based with built-in objects.
- Supports functions, arrays, and objects.
Internet - Concepts and Overview
Keywords
JavaScript has reserved words called **keywords** which are part of the syntax.
Examples:
- `var`, `let`, `const`: Variable declarations
- `if`, `else`, `switch`: Conditional logic
- `for`, `while`, `do`: Loops
- `function`, `return`, `break`, `continue`
Internet - Concepts and Overview
Variables
Variables store data values.
Declaration methods:
```javascript
var x = 5;
let y = 10;
const z = 15;
```
- `var`: Function-scoped (older usage)
- `let`: Block-scoped (modern usage)
- `const`: Block-scoped, read-only
Internet - Concepts and Overview
Data Types
JavaScript supports several data types:
- **Primitive Types**: `Number`, `String`, `Boolean`, `Null`, `Undefined`, `Symbol`, `BigInt`
- **Objects**: Arrays, Functions, Dates, etc.
Example:
```javascript
let name = "John"; // String
let age = 25; // Number
let isStudent = true; // Boolean
let x; // Undefined
let y = null; // Null
```
Internet - Concepts and Overview
Constants
Constants are declared using `const` and cannot be reassigned.
Example:
```javascript
const PI = 3.14159;
```
- Must be assigned at declaration.
- Block-scoped like `let`.
Internet - Concepts and Overview
Comments
Comments are used to explain code.
**Single-line comment**:
```javascript
// This is a comment
```
**Multi-line comment**:
```javascript
/* This is
a multi-line comment */
```
Internet - Concepts and Overview
JavaScript Conditional Statements
Used to make decisions based on conditions.
**if statement**:
```javascript
if (x > 0) {
console.log("Positive");
```
**if-else**:
```javascript
if (x > 0) {
console.log("Positive");
} else {
console.log("Not positive");
```
**switch**:
```javascript
switch(day) {
case 1: console.log("Monday"); break;
case 2: console.log("Tuesday"); break;
default: console.log("Other day");
```
Internet - Concepts and Overview
Different Types of Loops
**for loop**:
```javascript
for (let i = 0; i < 5; i++) {
console.log(i);
```
**while loop**:
```javascript
let i = 0;
while (i < 5) {
console.log(i);
i++;
```
**do-while loop**:
```javascript
let i = 0;
do {
console.log(i);
i++;
} while (i < 5);
```
Internet - Concepts and Overview
Break & Continue Statement
**break**: Exits the loop immediately.
```javascript
for (let i = 0; i < 5; i++) {
if (i === 3) break;
console.log(i);
```
**continue**: Skips to the next iteration.
```javascript
for (let i = 0; i < 5; i++) {
if (i === 3) continue;
console.log(i);
```