JavaScript Fundamentals. Function expression vs. Function declaration

JavaScript Fundamentals. Function expression vs. Function declaration

In JavaScript, we have three ways to write any functions: function declaration, function expression, and arrow functions. In this tutorial, you'll learn JavaScript Fundamentals. Function expression vs. function declaration.

In JavaScript, we have three ways to write any functions: function declaration, function expression, and arrow functions.

But I focused on the function expression and function declaration concept in this article.

Before talking about the key differences between them let see how they look.

Function Declaration

function foo(){
alert('hello')
}
foo();

The way is to write a function declaration is shown above. What we see?

  1. Function Declarations begins with the keyword “function”.
  2. You don’t need any variable assignment for it.

Function expression

let name = function foo(){
alert('hello')
};
foo();

javascript coding javascript-tips

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

7 Tips to Write Clean JavaScript Code

Who Else Wants to Write Clean JavaScript Code? In this Javascript tutorial, you'll see 7 Tips to Make Your Coworkers Fall in Love With Your Code.

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

7 Simple JavaScript Tips for Optimizing Your Code

You may not know about these tips 7 Simple JavaScript Tips for Optimizing Your Code

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.

Static Code Analysis: What It Is? How to Use It?

Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.