DEV Community

Elid
Elid

Posted on • Edited on

Functions for beginners

JS functions are a block of code that can be reused anywhere in your code, one of the building blocks of JS the example will be a function declaration.

Example:
// Declaring a function
function twoNumbers(num1 , num2) {
return num1 * num2
}

// Calling the function
twoNumbers(10, 2);

//This code would output 20;

So you see from the example you put in the parameters whatever two numbers you like to put (num1, num2).Then when you are ready to call the function in the argument twoNumbers(10, 2) or whatever two numbers you like output it to the console in your browser.

console.log(twoNumbers(10, 2));

This will output in the console I use chrome so I click ctrl + shift + i

You can do the same in ES6 Arrow Functions which will be much more less code and no return statement needed if is one line.

// Arrow function
const twoNumbers = (num1 , num2) => num1 * num2;
console.log(twoNumbers(10, 2)); //20

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

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

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay