What dah Function?
By: Amira de Moya
There came a moment in life where I decided I needed a change. I found myself exploring different career paths on the web when I came across a blog on digital nomads. The picture of the girl on the beach, a new country, the hot sun, a coconut in one hand, computer on her lap, working on something that made a difference in the world (I imagined), just drew me in.
Months later it was Day 1 of Flatiron School Software Engineer Intensive. After making it through a month and a half of Prep Work, I was finally here and boy, did reality set in fast with JavaScript. I was doing fifteen-hour days and was really feeling like an imposter. For the life of me I could not grasp functions. I know this might sound very basic but as a Singer/Songwriter who dropped her computer science class in college after just one class, transitioning into tech would not be easy. I knew this! I was not deceived by the clever marketing that targeted my social media. However, with perseverance, a lot of practice, and Google, the synapse in my brain fired and functions, it finally clicked. So, if you are where I was, wondering if this is for you, head heavy with Imposter Syndrome, asking yourself “What Dah Function?”
Function
A function, a basic yet integral fabric of JavaScript is an action word. Instead of performing similar tasks individually, writing repetitive code, a function allows us to group similar tasks together. Then, when we call the function everything inside the swirly brackets {} gets executed giving us a result.
Function Declaration
A basic function is created with an expression that begins with the keyword function. It can be an anonymous or a named function as noted below.
function greet(){
console.log('Hello JavaScript Beginner');
}
greet();
// Hello JavaScript Beginner
or it can have a parameter or multiple parameters. A function has a body that contains a block of code to be executed once the function is called.
function greet(name){
console.log('Hello ‘ + name);
}
greet(‘Tavian’);
//Hello Tavian.
function greet (name, lastName) {
console.log('Hello ' + name + ' ' + lastName);
}
greet('Tavian', 'Braddick');
//Hello Tavian Braddick
Source:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions
Eloquent JavaScript Marjin Harvebeke
Top comments (0)