QUICK & EASY GUIDE TO FUNCTIONS IN JAVASCRIPT

Daminda Dinesh Imaduwa Gamage
5 min readMay 4, 2022
Photo by Luca Bravo on Unsplash

What are JavaScript functions?

Functions are one of the main building blocks in JavaScript. Functions can have different syntaxes. In this post, we are going to look at some useful points that every developer should know.

The function is a statement that takes an input, makes use of those input/inputs, and returns a useful output.

This is NOT a function. But, a procedure

function greeting(){
console.log(“Hello World”)
}

This is function

function greeting( str ){
return str;
}

Is function an object?

Simply, the function is an object in JavaScript. It is a Function object. But, probably, you may have never used a Function constructor to create a function object as follows:

const print = new Function(‘str’, ‘return str’);

console.log(print(“hello world”))

This will create the print function dynamically. However, creating a function like this is not recommended due to a lack of security. Therefore, most JavaScript programmer uses the function keyword to declare a new function.

As I mentioned before every function in JavaScript is an object. You can test…

--

--