DEV Community

Cover image for JavaScript Chapter 6 - Creating JavaScript Functions
Dzun N
Dzun N

Posted on

JavaScript Chapter 6 - Creating JavaScript Functions

In this chapter 6 basic javascript learning tutorial we will continue our discussion of the basic tutorial. Previously we have discussed about other basic javascript tutorials from chapter 1 to chapter 5. in this tutorial to learn basic javascript chapter 6 we will discuss about "Creating Functions in JavaScript".

What is a function? maybe some of my friends still don't know the meaning of a function, so I will review a little about the meaning of function

DEFINITION OF FUNCTION IN JAVASCRIPT

A function is a facility in every programming to create a command whose function we can use repeatedly indefinitely. As long as the page is still connected to the function in question.

CREATE A FUNCTION IN JAVASCRIPT

To create functions in javascript, there are several things that must be understood first. Namely about writing functions in javascript. The following is an example of a function writing format in javascript.

<script> 
/Create Javascript function
function name _function(){ 
// the contents of the function are made here
} 
</script>
Enter fullscreen mode Exit fullscreen mode

As we have seen in the example above. To create a function the writing must be preceded by a syntax function then followed by the name of the function to be created. And the contents of the function are written in curly braces "{}". Here is a simple example of using a javascript function.

image

Consider the example above

function tampilkan_nama(){ 
return "Nurroin's Blog" }
Enter fullscreen mode Exit fullscreen mode

We create a function named "showname ()" which contains the command to return the string "Script Kiddies". So when the show_name () function is called, the result is 'Nurroin's Blog'

image

CONCLUSION

That's how to create a function in javascript, in essence, we have to create a function first, then the name of the function and the contents of the function are located in curly brackets (). And we just call the function and in the example above I print the function display name using document.getElementById

Top comments (0)