JAVASCRIPT Tutorial

Declaration

A declaration is a statement that introduces a new entity to a program, such as a variable, a function, or a class. In JavaScript, declarations use the function keyword followed by the function name, parameters, and code block.

Key Concepts:

  • Function keyword: The function keyword declares a new function.
  • Function name: The name of the function, which is used to call it.
  • Parameters: Optional input values that the function can receive. Parameters are enclosed in parentheses after the function name.
  • Code block: The block of code that executes when the function is called, enclosed in curly braces { }.

Syntax:

function function_name(parameters) {
  // Code block
}

Example:

function addNumbers(num1, num2) {
  return num1 + num2;
}

Explanation:

This JavaScript code defines a function called addNumbers that takes two parameters, num1 and num2. It returns the sum of the two numbers.