Lesson 1: JavaScript Basics
1.1 Introduction to JavaScript
JavaScript is a versatile programming language used for web development, server-side programming, and even mobile app development. It is known for its ability to make web pages interactive.
1.2 Why Learn JavaScript?
- Client-Side Scripting: JavaScript runs in the browser, making web pages dynamic and interactive.
- Versatile: Used for front-end, back-end (Node.js), and mobile app development (React Native).
- Large Community: Extensive libraries and frameworks like React, Angular, and Vue.js.
- Beginner-Friendly: Easy to learn and widely supported.
1.3 Setting Up JavaScript
JavaScript can be run directly in the browser or using Node.js for server-side development.
Step 1: Running JavaScript in the Browser
- Open your browser's developer tools (F12).
- Go to the Console tab.
- Type the following code and press Enter:
console.log("Hello, World!");
1.4 Variables and Data Types
JavaScript uses let
, const
, and var
to declare variables.
let name = "Alice";
const age = 25;
var isStudent = true;
Data Types:
- Number: Integers and decimals (e.g.,
10
,3.14
). - String: Text (e.g.,
"Hello"
). - Boolean:
true
orfalse
. - Object: Key-value pairs (e.g.,
{ name: "Alice", age: 25 }
). - Array: Ordered lists (e.g.,
[1, 2, 3]
).
1.5 Basic Operations
JavaScript supports basic mathematical operations:
let x = 10;
let y = 5;
console.log(x + y); // Addition
console.log(x - y); // Subtraction
console.log(x * y); // Multiplication
console.log(x / y); // Division