Introduction to JavaScript
JavaScript is a widely used programming language that powers the interactive features and dynamic content on websites. It was created by Brendan Eich in 1995 and has since become an essential tool for web developers. In this blog post, we will explore the fundamental concepts of JavaScript and its key features.
Variables
In JavaScript, variables are used to store values and data. They are declared using the var
, let
, or const
keywords. The var
keyword declares a variable with function scope, while let
and const
declare variables with
block scope. The const
keyword is used for variables that can't be reassigned.
// Variable declaration and assignment
var age = 25
let name = 'John'
const PI = 3.14
Data types in JavaScript
JavaScript has several built-in data types. The primitive types include string, number, boolean, null, and undefined. Additionally, JavaScript has two composite data types: object and array. Objects are collections of key-value pairs, while arrays are ordered lists of values.
let message = 'Hello, World!'
let quantity = 10
let isLogged = true
let person = { name: 'John', age: 30 }
let fruits = ['apple', 'banana', 'orange']