JavaScript Basics

January 10, 2024
programming
beginnerprogramming

Learn the fundamentals of JavaScript programming language

JavaScript Basics

JavaScript is a versatile programming language that powers the web. Let's start with the fundamentals.

Variables and Data Types

JavaScript has several data types:

javascript
// Numbers
let age = 25;
const pi = 3.14159;

// Strings
let name = "John Doe";
const message = 'Hello World';

// Booleans
let isActive = true;
const isComplete = false;

// Arrays
let fruits = ["apple", "banana", "orange"];
const numbers = [1, 2, 3, 4, 5];

// Objects
let person = {
  name: "John",
  age: 30,
  city: "New York"
};

Functions

Functions are reusable blocks of code:

javascript
// Function declaration
function greet(name) {
  return `Hello, ${name}!`;
}

// Arrow function
const add = (a, b) => a + b;

// Function with default parameters
function createUser(name, age = 18) {
  return { name, age };
}

Key Concepts

Practice Exercises

  1. Create a function that calculates the area of a circle
  2. Write a function that reverses a string
  3. Implement a simple calculator with basic operations

Next Steps

Once you master these basics, you can move on to: