Just wrap in parenthesis and call the function.

let theNumber2 = (() => { return 2; })();

console.log(theNumber2);

Answer from Nina Scholz on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Arrow_functions
Arrow function expressions - JavaScript - MDN Web Docs
February 21, 2026 - An arrow function expression is ... and deliberate limitations in usage: Arrow functions don't have their own bindings to this, arguments, or super, and should not be used as methods. Arrow functions cannot be used as constructors. Calling them with new throws a ...
🌐
W3Schools
w3schools.com › js › js_arrow_function.asp
JavaScript Arrow Functions
In this case, this does not refer to the person object. ... Parentheses are required for zero or multiple parameters. Arrow functions do not bind this. Arrow functions are not hoisted. You have now learned the most important concepts about JavaScript functions.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Arrow functions, the basics
April 14, 2022 - Arrow functions can be used in the same way as Function Expressions. ... let age = prompt("What is your age?", 18); let welcome = (age < 18) ? () => alert('Hello!') : () => alert("Greetings!"); welcome(); Arrow functions may appear unfamiliar ...
🌐
Programiz
programiz.com › javascript › arrow-function
JavaScript Arrow Function
JavaScript arrow functions are a concise syntax for writing function expressions. Here's a quick example of the arrow function. You can read the rest of the tutorial for more. // an arrow function to add two numbers const addNumbers = (a, b) => a + b; // call the function with two numbers const result = addNumbers(5, 3); console.log(result); // Output: 8 · In this example, addNumbers() is an arrow function that takes two parameters, a and b, and returns their sum.
🌐
GeeksforGeeks
geeksforgeeks.org › arrow-functions-in-javascript
Arrow functions in JavaScript | GeeksforGeeks
Use arrow functions for callbacks and array methods to improve readability. Avoid arrow functions in object methods if this needs to refer to the object itself. Prefer arrow functions in functional programming patterns for their concise syntax. Use rest parameters for variadic functions when arguments are needed. ... JavaScript ...
Published   May 17, 2025
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-arrow-functions
Getting Started with Arrow Functions in JavaScript
There's no difference between calling ... of the arrow function is this: ... Enumerate the parameters (param1, param2, ..., paramN) , then put the arrow =>, and on the right side write the body { ......
🌐
freeCodeCamp
freecodecamp.org › news › javascript-arrow-functions-in-depth
How to Use JavaScript Arrow Functions – Explained in Detail
November 30, 2023 - I’ll compare the arrow function ... you need to create a function in JavaScript, the main method is to use the function keyword followed by the function name as shown below:...
🌐
DigitalOcean
digitalocean.com › community › tutorials › understanding-arrow-functions-in-javascript
Understanding Arrow Functions in JavaScript | DigitalOcean
August 28, 2021 - Like traditional function expressions, arrow functions are not hoisted, and so you cannot call them before you declare them. They are also always anonymous—there is no way to name an arrow function.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_arrow_functions.htm
JavaScript - Arrow Functions
In the below code, we use the ternary operator, and based on the boolean value of the 'isMul' variable, we assign the arrow function expression to the 'func' variable. After that, we use the 'func' variable to call the arrow function stored in that.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript arrow functions
A Gentle Introduction to JavaScript Arrow Function
November 14, 2024 - function show() { return (x) => x + arguments[0]; } let display = show(10, 20); let result = display(5); console.log(result); // 15Code language: JavaScript (javascript) The arrow function inside the show() function references the arguments object.
🌐
SitePoint
sitepoint.com › blog › javascript › arrow functions in javascript: how to use fat & concise syntax
Arrow Functions in JavaScript: Fat & Concise Syntax — SitePoint
November 15, 2024 - Arrow functions aren’t just a fancy new way of writing functions in JavaScript. They have their own limitations, which means there are cases when you don’t want to use one. The click handler in the previous demo is a case in point, but it’s not the only one. Let’s examine a few more. Arrow functions don’t work well as methods on objects. Here’s an example. Consider this netflixSeries object, which has some properties and a couple of methods. Calling console.log(netflixSeries.getLikes()) should print a message with the current number of likes, and calling console.log(netflixSeries.addLike()) should increase the number of likes by one and then print the new value with a thankyou message on the console:
🌐
YouTube
youtube.com › watch
#46 How to use Arrow Functions | JavaScript Full Tutorial - YouTube
In this lesson we'll learn all about Arrow Functions, arrow functions are a new modern way of writing functions, they provide a cleaner and more concise synt...
Published   November 29, 2021
🌐
Medium
ishwar-rimal.medium.com › call-bind-and-apply-with-arrow-function-in-javascript-4e614456d5f5
Call, Bind, and Apply with Arrow function in JavaScript. | by Ishwar Rimal | Medium
June 20, 2023 - Call, Bind, and Apply with Arrow function in JavaScript. If you’re a lazy dev like me, then you might have taken some good amount of time and experience before starting to use call(), bind() and …
🌐
ui.dev
ui.dev › arrow-functions
Arrow Functions in JavaScript - Fireship
What that means is that typically the this keyword Just Works™ without you having to worry about what context a specific function is going to be invoked in. So by using arrow functions in the updateLanguage method, we don't have to worry about this which means we don't have to call .bind anymore.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript arrow functions
JavaScript Arrow Functions
November 14, 2024 - function show() { return (x) => x + arguments[0]; } let display = show(10, 20); let result = display(5); console.log(result); // 15Code language: JavaScript (javascript) The arrow function inside the show() function references the arguments object.
🌐
YouTube
youtube.com › watch
Learn JavaScript ARROW FUNCTIONS in 8 minutes! 🎯 - YouTube
// arrow functions = a concise way to write function expressions// good for simple functions that you use only once00:00:00 i...
Published   November 13, 2023
🌐
LogRocket
blog.logrocket.com › home › how and when to use javascript arrow functions
How and when to use JavaScript arrow functions - LogRocket Blog
February 17, 2025 - Since the arrival of the ES2015 standard, JavaScript programmers have had arrow functions in their toolbox. Their main strength is the abbreviated syntax; you don’t need the function keyword, and with implicit return you don’t need a return statement. The lack of a this binding can cause confusion, but is also handy when you want to preserve the enclosing this value to another function when passed as a callback.
🌐
TOOLSQA
toolsqa.com › javascript › javascript-arrow-function
What is JavaSCript Arrow function and How to use it with examples?
It should show the following output: As is evident from the above screenshot, the same task of the map, reduce and filter can be achieved with a much cleaner syntax with the help of "Arrow" functions. We know that the asynchronous callbacks or promises contain a great deal of "function" and "return" keywords. When using promises, we generally use function expressions to chain these calls as follows: <html> <body> Demonstrating promise consumer using .then() method in javascript:</br> <script type="text/javascript"> function createDivAndAppendText(divID, text) { const outPutElem = document.crea