DEV Community

Cover image for Functions Blog
Charles Eugene
Charles Eugene

Posted on

Functions Blog

What's up yall!?? Charles here! So today we're gonna talk about CONJUCTION CONJUCTION WHAT ARE FUNNNNCTIONS???? (Yeah I'm old some of yall probably didn't get that but do your research on that haha I'm just a bill!)

Image description

But aye what did Cam'Ron say BACK TO BIDNESS!!
Functions are one of the core concepts in JavaScript. They allow you to encapsulate code that you can reuse, pass as arguments, return from other functions!

Now I'm going to show you how to use a Funk-tion
Image description

Use the function keyword followed by the name of the function, followed by parentheses () and curly braces {}. It really is pretty easy well this part ain't nothing to it, just do it!
Image description

But seriously yall this is a safe space! What's on your mind? I know the world is super crazy for everyone! But hey I'm here for ya big or small lets talk functions or life I'm here!
Image description

But hey back to the cold world of FUNCTIONS BRRRRRR! There are 4 different ways to create a function in JavaScript. Here we go!!
Image description

  1. Function Declaration
  2. Function Expression
  3. Arrow Function
  4. Function Constructor

So below I will be listing an examples of each of these Functions

Function Declaration
A function declaration defines a function with the specified parameters.

function greet(name) {
return "Hello, " + name + "!";
}

console.log(greet("Ash")); // prints = Hello, Ash!

Image description

Function Expression

A function expression defines a function as part of a larger expression

var multiply = function(a, b) {
return a * b;
};

console.log(multiply(4, 4)); // prints = 16

Image description
(This is a 16 bit Sub-Zero btw just incase you didn't get it LOL)

So lets take a quick break before we get Back to BIDNESS!!

Image description

How we feeling about Function Declarations and Function Expressions so far? Me I'm feeling pretty good about it but if you have any questions I'm here hit my line people :D but yeah idk if you guys are into sports but my fantasy football team isn't doin to hot right now man :/ I started off 2-0 but I lost back to back games so I'm 2-2 but hopefully I get back on track haha! Like I said this is a safe space we can talk about anything! This is the coders life I'm learning the better your mood is the better you can code TRUST ME ON THAT!! But aye you know the phrase here "BACK TO BIDNESS"!!!
Image description

Arrow Function

Arrow functions provide a shorter syntax for writing function expressions. They are always anonymous and have some differences in how this is handled compared to regular functions.

let add = (a, b) => a + b;

console.log(add(5, 3)); // prints = 8

Image description

Function Constructor

A function constructor in JavaScript is a special type of function that is used to create new function objects dynamically. It provides a way to define a function's parameters and body as strings, and then return a new function based on these inputs.

let sum = new Function('a', 'b', 'return a + b;');

console.log(sum(10, 12)); // prints = 22

Image description

(GUYS DO NO NOT JUDGE ME I DO NOT LISTEN TO TAY SWIFT LIKE THAT BUT THAT OLD TAY SWIFT WAS FIRE!!! OUR SONG IS SLAMMIN SCREEN DOOR LOL!!!)

But hey how we feeling about Arrow Functions and Function Constructors? I will die on the this hill! This is a safe space any questions about functions or life in general! Just a life tip drink your water guys make sure to get up and walk for at least an hour especially if you're feeling down, I promise you'll feel better! Hey guys and gals I love yall just incase no one has told you today!

Image description

Top comments (0)