DEV Community

Cover image for Functions - JavaScript Series - Part 16
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

11 4

Functions - JavaScript Series - Part 16

Function is a block of code where we write some tasks or a single task to do. Function run only when we call it. Sound confusing ?

If no then just skip next two slide/lines.

Do you remember using console.log ? What do you think this is ? When we pass something on the “” in console.log then we can see it is printing on the console right ? How this happens?

Actually there is some native parts of JavaScript. Where there is function and we call it using it and pass the value to show in the console. So we are already using the function right ? Do you understand now ?

Now writing function in JavaScript is really easy. Just start with function keyword. This is reserve keyword for initialing a function like we initial variable using var.

It is like giving name of variable. We’ll give a name after function keyword. Then function need some parameter to pass. We can leave it blank for now and our code will be –

function nameOfFunction() {
//Block of code
}
Enter fullscreen mode Exit fullscreen mode

Now lets write a function –

Alt Text

See the result in browser console

Alt Text

Can you write some basic functions now ?

You can see the graphical version here

Source Codes - { Check commits }

GitHub logo nerdjfpb / javaScript-Series

A tutorial for JavaScript Beginners

javaScript-Series

A tutorial for Absolute Beginners of JavaScript.

You can find the total pdf in - Here

You can check the commits to find the part by part codes.

Blogs

Day 1
  • Day 1 - What is JavaScript?
Day 2
  • Day 2 - JavaScript Types?
Day 3
  • Day 3 - Javascript Types Cont.
Day 4
  • Day 4 - Javascript Types Cont.
Day 5
  • Day 5 - Javascript Comparisons
Day 6
  • Day 6 - Javascript Variables
Day 7
  • Day 7 - More About Variables
Day 8
  • Day 8 - Conditional Statement
Day 9
  • Day 9 - More Conditional Statement
Day 10
Day 11
Day 12
Day 13
Day 14
Day 15
Day 16
Day 17

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more