Day -5 JavaScript Fundamentals
Day -5 JavaScript Fundamentals
1. Introduction to JavaScript
JavaScript is a versatile, dynamic programming language used to make web pages interactive. Unlike
HTML and CSS, which are used for structure and styling respectively, JavaScript is a scripting language
that allows you to control the behavior of web pages. It is an essential technology used in web
development and runs on all modern browsers. JavaScript is primarily used for front-end
development to create dynamic, interactive user experiences but can also be used for back-end
development through technologies such as Node.js.
2. Variables
In JavaScript, variables are containers that hold data values. You declare a variable using one of three
keywords: var, let, and const. Each has its own behavior in terms of scoping and reassignment.
var: The oldest form of declaring variables, var is function-scoped. It can be redeclared and
reassigned within its scope.
let: Introduced in ES6 (ECMAScript 2015), let is block-scoped, meaning it only exists within
the block {} where it's defined. It can be reassigned but not redeclared.
const: Also block-scoped, but once assigned, a const variable cannot be reassigned, making it
ideal for immutable values.
Example:
3. Data Types
JavaScript supports various data types, including primitive types and non-primitive (reference) types.
Primitive Types: These are simple types that represent a single value.
o undefined: Represents a variable that has been declared but not yet assigned a
value.
4. Operators
Operators in JavaScript are symbols that perform operations on variables and values. The most
common types of operators are arithmetic, comparison, and logical operators.
Example:
let a = 5;
let b = 3;
Example:
Example:
console.log(!true); // false
5. Functions
Functions in JavaScript allow you to encapsulate reusable blocks of code. Functions can be declared
in various ways.
Function Declaration:
function greet(name) {
Example:
function add(a, b) {
return a + b;