Skip to content
the poor coder

arrow function - one line and no parameters

Poor Man
Published
Reading time
1 min read

Arrow Function - One Line and No Parameters#

Arrow functions in JavaScript provide a concise and more readable way to write functions. They are commonly used in functional programming and are especially helpful when working with arrays and objects.

In this case, we want to create an arrow function that has no parameters and only one line of code. This can be done in the following way:

Text

const funcName = () => console.log('Hello World!'); 

In the above code, we declare a constant variable called funcName and assign it an arrow function. The parentheses indicate that there are no parameters, and the code after the arrow is the function body. In this case, we're simply logging a string to the console.

Another way to write this function would be to use the return keyword:

Text

const funcName = () => {
  return 'Hello World!';
};

This code is equivalent to the previous one. The only difference is that we're using braces to define the function body and explicitly returning a value.

One important thing to note when working with arrow functions is that they do not have their own this keyword. Instead, they inherit it from the enclosing lexical scope. This can sometimes lead to unexpected behavior if you're not careful.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC