JS101–1 Making Javascript Function Simple

Image by Nenad Mećava from Pixabay

Javascript functions are easy. Functions can perform calculations, manipulate data, and can store them. It is a block of code that executes when it receives a call.

Javascript function starts with a keyword function at start and name of the function after a keyword, it is called “function declaration” or function definition.

function nameOfFunction(){    return "You have just called a function";
}
nameOfFunction()

The above function will print “You have just called a function”.

Dynamically, parameters can be passed to the function to provide values at run time. The parameters are unlike other languages, it does not require parameter data types explicitly. Javascript will automatically assign the data type to the variable or parameter.

function nameOfFunction(parameter){
return "Value of Parameter is : " + parameter;
}
nameOfFunction("Dynamic Value")

Upon calling of above function it will print “Value of Parameter is : Dynamic Value”.

As earlier mentioned, the calculation can be performed from the javascript function, an example would be

function myFunction(a, b) {
// Function returns the product of a and b
return a * b;
}
// Function is called, return value
myFunction(45, 55);
// furthermore, the returned value can be store in variable
var value = myFunction(45,55)
// this will print 100 in console.
console.log(value)

Even more, you can perform more complex calculations as below

function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
var celsiusValue = toCelsius(77);console.log(celsiusValue)

Javascript can perform almost any calculation and any valid mathematics expression.

--

--

--

Raheel Khan is founder of Mrasta Inc and Leading Web Developer who loves to convert ideas into business and provide great support to the newbies.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

⚙️ Integration Tests on Node.js CLI: Part 3 – Inter Process Communication

Izaak’s Standard CSS Reset

I am getting cheaper pricing for hosting from other providers. Why is your price high?

How To Fix the Most Common Angular Performance Problems Like a Doc

Let’s Develop a Video Chat App using JavaScript and WebRTC

How to install Node.js on Mac / Windows

Make a Pinterest Chrome Extension

Quarkus in practice — Starting with Quarkus

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Raheel Khan

Raheel Khan

Raheel Khan is founder of Mrasta Inc and Leading Web Developer who loves to convert ideas into business and provide great support to the newbies.

More from Medium

Introduction to JavaScript

WHY JAVASCRIPT?

javascript and its uses

JavaScript Basics

duckett books for html css & javascript

JavaScript and Version Controlling