0% found this document useful (0 votes)
2 views

JSFunctionNotes

In JavaScript, a function is a set of statements that performs a specific task and returns a result, helping to avoid code repetition. Functions can be built-in or user-defined, created using the 'function' keyword followed by the function name and parameters. The document also provides a syntax example for defining a function and mentions Immediately Invoked Function Expressions (IIFE).

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JSFunctionNotes

In JavaScript, a function is a set of statements that performs a specific task and returns a result, helping to avoid code repetition. Functions can be built-in or user-defined, created using the 'function' keyword followed by the function name and parameters. The document also provides a syntax example for defining a function and mentions Immediately Invoked Function Expressions (IIFE).

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

-----------------------------------------------------------------------------------

-------------------------------
Functions
-----------------------------------------------------------------------------------
-------------------------------

Functions:->A function in javascript is a collection/set of some statement which


takes some input, doing a specific
task/computation and displaying/return the result/output. The objective
of writing a function is to avoid
writing of same code again and again to achieve the same objective for
different input i.e., to avoid
repetition of code.
->JavaScript has number of built-in functions. But, JavaScript allows a
programmer to create a user-defined
functions.
->"function" is the keyword which is used to create a function in
JavaScript.
->To craete a function is JavaScript, firstly write "function" keyword
and the function name followed by a
sepace i.e., function keyword and function should be separated by a
space. There will be a parenthesis just
after function name which consists of parameters. The function body
will be inside curly braces which is
given just after parenthesis.
->Syntax for creating a function in JavaScript :

function function-name(parameter1, parameter2)


{
//function body.
//set of instruction.
}

Exaple: function addNumber(number1, number2)


{
return number1+number2;
}
console.log( addNumber(19,20) );

o/p : 39

IIFE(Immediately invoked Function Expression) :

You might also like