Tech Study

Functions in JavaScript

Functions in JavaScript

In functions in javascript are reusable blocks of code that perform specific tasks. It is defined using the function keyword followed by a set of parentheses that can include the function name and any parameters to the function. A function can pass one or more values ​​and return a value when it is finished executing.

Functions in JavaScript With Examples

Syntax:

function function_name(parameter1, parameter2, parameter3) {

  // executable code

  // can reference parameters and other variables

  return result; 

}
  • function keyword: 

This keyword is used to define a new function.

  • function_name: 

The name of the function.It should be descriptive and start with a lowercase letter.

  • Parameter1, Parameter2, Parameter3: 

The input parameters of the function. Optional, but if optional, must be enclosed in parentheses and separated by commas.

Example:

let person = {

  name: "Nisha",

  sayHello: function() {

    console.log("Hello, my name is " + this.name + ".");

  }

};

person. sayHello();

Output:

Hello, my name is Nisha.

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more