Javascript Functions – Basic Explaination

Ok. So you`re starting with JavaScript. It can be confusing and hard in the beginning. However, it`s possible to get by the first steps pretty fast if you find something to develop. Personally i made a budget for my private economy, it`s something you gonna use, and its sort of fun to try out new functions and operators. Also, don`t care if its best practice or if it`s a better way to solve this, you got to start somewhere.

A function

This is a basic function adding two numbers.

function addNumbers(a, b) {
   return a + b
}

addNumbers(4, 6) // Returns 10
addNumbers("hello", "there") // Returns "hellothere"

Above we have two arguments ( A and B) and inside the function we do something with A and B. As you see it will also add a and b if we run it with two strings. For me it helped a lot to write basic functions over and over again. Pass inn words, numbers, arrays and what not, see what happens.

Just play around and have fun. You can name the function whatever. A and B could also be width and height which makes it more understandable. Like this:

function addNumbers(width, height) {
   return width + height
}

More documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function

Other posts:

Hide Folders and Files With Robots.txt

Adding Meta Tags to Next.js With Headless WordPress.