📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

4️⃣ Functions (JavaScript)

🔹 What is a Function?

A function is a block of code that performs a specific task and can be reused.

👉 Instead of writing code again and again, you call a function.

function greet() {
console.log("Hello!");
}
greet(); // calling function

🔹 Function Declaration

Defined using the function keyword.

function add(a, b) {
return a + b;
}console.log(add(5, 3)); // 8

✔️ Can be called before declaration (hoisting)


🔹 Function Expression

Function stored inside a variable.

const multiply = function(a, b) {
return a * b;
};console.log(multiply(4, 3)); // 12

❌ Cannot call before definition


🔹 Arrow Functions (ES6)

Short and modern syntax.

const divide = (a, b) => {
return a / b;
};console.log(divide(10, 2)); // 5

👉 Short form:

const square = x => x * x;

🔹 Parameters & Arguments

  • Parameters → variables in function
  • Arguments → actual values passed
function greet(name) { // parameter
console.log("Hello " + name);
}greet("Aditya"); // argument

🔹 Return Values

Functions can return a value.

function sum(a, b) {
return a + b;
}let result = sum(2, 3);
console.log(result); // 5

🔹 Default Parameters

Set default value if no argument is passed.

function greet(name = "Guest") {
console.log("Hello " + name);
}greet(); // Hello Guest
greet("Aditya"); // Hello Aditya

🔹 Callback Functions

A function passed as an argument to another function.

function greet(name, callback) {
console.log("Hello " + name);
callback();
}function sayBye() {
console.log("Goodbye!");
}greet("Aditya", sayBye);

🧪 Practice Programs

1️⃣ Age Calculator

function calculateAge(birthYear) {
let currentYear = new Date().getFullYear();
return currentYear - birthYear;
}let age = calculateAge(2000);
console.log("Your age is:", age);

2️⃣ Simple Interest Calculator

Formula:
👉 SI = (P × R × T) / 100

function simpleInterest(p, r, t) {
return (p * r * t) / 100;
}let si = simpleInterest(10000, 5, 2);
console.log("Simple Interest:", si);


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes