DEV Community

Bhuvana Sri R
Bhuvana Sri R

Posted on

Day 3 of Javascript

Function

  • Function is block of code with set of instruction.
  • Once write the instruction and call it many times.
  • Function is a resuability code design to perform a specific task.
  • Function execute when they are called or invoked.

Syntax for function

function funname()
{
//set of instruction
}
Enter fullscreen mode Exit fullscreen mode

Exaplanation:

  • function is a keyword or reserve word.
  • funname is a function name.we can give any name but it want to be understandable.
  • ()->function bracket.Inside the bracket we give parameters(inputs).
  • {}->inside write a set of instruction.

Example:
Without parameter

function sample()
{
   console.log("Hello");
}
sample() //function calling statement
Enter fullscreen mode Exit fullscreen mode

with parameter

function add(a,b)
{
console.log(a+b);
}
add(10,20)
Enter fullscreen mode Exit fullscreen mode

Type of :
typeof is operator it return the types of variable.
Example:
console.log(typeof(10))//number10

Top comments (0)