DEV Community

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

Posted on • Originally published at blog.nerdjfpb.com

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!

Top comments (0)