DEV Community

Cover image for Functions in JavaScript
svetlanatad
svetlanatad

Posted on

Functions in JavaScript

What are functions?

In JavaScript, a function is comparable to a procedure—a collection of statements that carry out an action or compute a value. Basically, a function is a method to perform a desired algorithm. However, in order for a process to be considered a function, it must accept an input and produce an output with an evident connection between the input and the result. This blog post firmly explains the most basic properties of a javascript function and

What is the correct way of using functions? How can we play with functions? What is their visibility scope? How are variables checked?

The function keyword is used to define a JavaScript function, which is then followed by the function's name and parenthesis (). Function names may also include underscores, dollar signs, and other characters (same rules as variables). Names of parameters may be included in parenthesis and separated by commas: (p1, p2, ...) Curly brackets enclose the code that the function will execute: {} The function definition lists the function parameters between parentheses (). When a function is called, values are passed to it as arguments.
The arguments (the parameters) behave as local variables within the function. When "something" invokes (calls) the function, the code inside will run: When something happens (when a user clicks a button),
When JavaScript code calls (invokes) it,
Automatically (self invoked) (self invoked).
A return statement in JavaScript causes the function to terminate. If a statement called the function, JavaScript will "return" to run the code that came after the statement that called the function. Frequently, functions calculate a return value. The caller is "returned" the return value. Variables can be checked by .typeof(var) built in function where var is the variable name.
This is a very rough explanation on how functions work, but it still gets the job done. ƪ(˘⌣˘)ʃ
Thank you.

Top comments (0)