Hackforge Academy

Category: javascript

Functions

Published on 29 Jun 2026

Explanation

Functions are reusable blocks of code that perform a specific task and can accept input through parameters.

Code:

function greet(name) {
  console.log('Hello ' + name);
}
greet('John');

Explanation

Functions can return values using the return statement.

Code:

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

Explanation

Variables declared inside a function have local scope and are accessible only within that function.

Code:

function demo() {
  let message = 'Hello';
  console.log(message);
}

Explanation

Variables declared outside functions have global scope and can be accessed throughout the program.

Code:

let company = 'HackForge';
function show() {
  console.log(company);
}

Explanation

Block scope, introduced with let and const, limits variable access to the block in which they are declared.

Code:

if (true) {
  let age = 25;
  console.log(age);
}

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community