WikiGalaxy

Personalize

JavaScript Functions

This introduction to JavaScript functions will cover the basics of declaring and invoking functions. A function in JavaScript is a block of code that can be reused, making your scripts more modular and manageable.


function greet(name) {
    console.log("Hello, " + name);
}
greet('World');
    

Console Output:

Hello, World

Variables and Constants

Introduction:

Understanding variables and constants is crucial in JavaScript. Variables can store data which can change over time, whereas constants are used for values that should remain static throughout the program execution.


let age = 25;
const birthYear = 1995;
age = 26; // age can be updated, but birthYear cannot
    

Console Output:

Updated Age: 26

Conditionals

Key Concepts:

Using conditionals like if-else statements allows you to execute different blocks of code based on certain conditions, which enhances decision-making capabilities within your JavaScript program.


let time = 10;
if (time < 12) {
    console.log("Good morning");
} else {
    console.log("Good afternoon");
}
    

Console Output:

Good Morning

Loops

Overview:

Loops are used in JavaScript to iterate through arrays or execute a block of code a specified number of times. The most commonly used loops include for, while, and do-while.


for (let i = 0; i < 5; i++) {
    console.log("Iteration " + i);
}
    

Console Output:

Iteration 0

Iteration 1

Iteration 2

Iteration 3

Iteration 4

Arrays

Details:

Arrays hold multiple values in a single variable and are an essential feature in JavaScript. They provide various methods for adding, removing, and manipulating elements within the array.


let fruits = ['Apple', 'Banana', 'Cherry'];
console.log(fruits[1]); // Outputs: Banana
    

Console Output:

Banana

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025