No, there is not. With ES6, you might be able to use an arrow function: ()=>{} which is a bit shorter.

If you really need this very often (you shouldn't?!), you can declare one yourself:

function noop(){}

and then refer to that repeatedly. If you don't want to clutter your scope, you can also use the Function.prototype function (sic!) which does nothing but constantly return undefined - yet that's actually longer than your function expression.

Answer from Bergi on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Arrow_functions
Arrow function expressions - JavaScript | MDN
For the purpose of formatting, you may put the line break after the arrow or use parentheses/braces around the function body, as shown below. You can also put line breaks between parameters. ... const func = (a, b, c) => 1; const func2 = (a, b, c) => ( 1 ); const func3 = (a, b, c) => { return 1; }; const func4 = ( a, b, c, ) => 1; Although the arrow in an arrow function is not an operator, arrow functions have special parsing rules that interact differently with operator precedence compared to regular functions.
🌐
GitHub
gist.github.com › wklug › 5b0a614835a7fb302cd4e2561b2d4246
ES6 - Empty Arrow functions return · GitHub
ES6 - Empty Arrow functions return · Raw · js-gist-04.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
QuickRef.ME
quickref.me › home › how to create an empty function in javascript - quickref.me
How to create an empty function in JavaScript - QuickRef.ME
In this Article we will go through how to create an empty function only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › arrow-functions-in-javascript
Arrow functions in JavaScript - GeeksforGeeks
Arrow functions in JavaScript are ... function that takes two numbers and returns their sum. ... An arrow function without parameters is defined using empty ......
Published   May 16, 2018
🌐
GitHub
github.com › nodejs › help › issues › 2235
Arrow function that "return this" returns an empty object · Issue #2235 · nodejs/help
October 16, 2019 - v10.16.3: Linux, running on fedora 30: Arrow function that "return this" returns an empty object. Here's a simple working demonstration: const one = { first: () => { console.log('first') return this }, second: () => { console.log('second...
Published   Oct 16, 2019
🌐
W3Schools
w3schools.com › js › js_arrow_function.asp
JavaScript Arrow Functions
This arrow function does the same thing as a regular function expression. ... You can remove the word function, the curly brackets and the return keyword. ... This works only if the function has only one statement.
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Arrow functions, the basics
There’s another very simple and concise syntax for creating functions, that’s often better than Function Expressions. It’s called “arrow functions”, because it looks like this:
🌐
ESLint
eslint.org › docs › latest › rules › no-empty-function
no-empty-function - ESLint - Pluggable JavaScript Linter
/*eslint no-empty-function: "error"*/ function foo() {} const bar = function() {}; const bar1 = () => {}; function* baz() {} const bar2 = function*() {}; const obj = { foo: function() {}, foo: function*() {}, foo() {}, *foo() {}, get foo() {}, set foo(value) {} }; class A { constructor() {} foo() {} *foo() {} get foo() {} set foo(value) {} static foo() {} static *foo() {} static get foo() {} static set foo(value) {} }
🌐
Stack Overflow
stackoverflow.com › questions › 74212347 › javascript-empty-arrow-function
JavaScript empty Arrow Function - Stack Overflow
Im new to JavaScript, and im trying to figure out if this is the correct syntax for an array method that takes in an empty arrow function as an argument. This code block will be used as a callback
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Learn Modern JavaScript Methods by Building Football Team Cards - Step 25 - JavaScript - The freeCodeCamp Forum
April 12, 2024 - It’s Have a extra function word and missing aero => after empty () parentheses. @Katerevrie ... ( ) => { } and function () {} are two types of functions that can be used as an empty callback function. The first type is called an arrow function.
🌐
Atlantbh Sarajevo
atlantbh.com › home › falsy and truthy values & arrow functions in js
Falsy and Truthy values & Arrow Functions in JS - Atlantbh Sarajevo
June 29, 2022 - The following construct: ... Truthy values are all others. Some examples are: {} (empty object), [] (empty array), function () {} (empty function), ‘0’ (string with 0 as value).
🌐
Simple Dev
simpledev.io › home › arrow functions (no parameters) – javascript
Arrow functions (no parameters) - JavaScript - Simple Dev
June 30, 2022 - To create an arrow function without arguments, first write a pair of parentheses, followed by a space and an equals sign and greater than sign right next to each other. After the arrow, add a space and a pair of curly braces…
🌐
SamanthaMing
samanthaming.com › tidbits › 47-arrow-functions-cheatsheet
ES6 Arrow Functions Cheatsheet | SamanthaMing.com
When you use the return keyword, it's called an explicit return. However, arrow functions up their game and allow something called implied return where the return keyword can be skipped.
Top answer
1 of 1
1
Hello Andrew, I too thought arrow functions were shorthand for function() {} when I was first introduced to them. But as it turns out, they do add some special functionality. Specifically when it comes to "this." This is a relatively big topic, so I won't go into crazy depth here. However I'll provide some additional resources that will hopefully get you on the right path. First of all, your code. Try removing the arrow function from: countWords: () => { return this.string.split(" ").length; } so it looks like this: countWords: function() { return this.string.split(" ").length; } So the question is, why does "this" return return an empty object instead of the myString object? The short answer is that since you're using an arrow function, "this" is bound to the countWords function/method instead of the myObject object. This is the first article (https://medium.freecodecamp.org/when-and-why-you-should-use-es6-arrow-functions-and-when-you-shouldnt-3d851d7f0b26) I'd suggestion reading. Specifically the Main benefit: No binding of ‘this’ section towards the bottom of the article. Here's an excerpt: In classic function expressions, the this keyword is bound to different values based on the context in which it is called. With arrow functions however, this is lexically bound. It means that it uses this from the code that contains the arrow > function. "this" is a very confusing and misunderstood aspect of JavaScript. If you want to go deeper into how it works, Kyle Simpson has written a book (available for free on GitHub) (https://github.com/getify/You-Dont-Know-JS/tree/master/this%20%26%20object%20prototypes) that goes deep into how "this" works. There are four rules to determine the context of "this": Is the function called with new (new binding)? If so, this is the newly constructed object. Is the function called with call or apply (explicit binding), even hidden inside a bind hard binding? If so, this is the explicitly specified object. Is the function called with a context (implicit binding), otherwise known as an owning or containing object? If so, this is that context object. Otherwise, default the this (default binding). If in strict mode, pick undefined, otherwise pick the global object. Treehouse also has a workshop on arrow functions (https://teamtreehouse.com/library/arrow-functions) that I'd recommend checking out if you haven't already done so. I hope this helps! If you have any additional questions, please let me/us know! Have a great weekend, Brandon
🌐
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 - You can do all of these using JavaScript arrow functions. In the above example, the function has no parameters. In this case, you must add a set of empty parentheses () before the fat arrow (=>) symbol.
🌐
Telerik
telerik.com › blogs › why-arrow-function-cannot-used-create-object-javascript
Why Arrow Function Cannot be Used to Create an Object in JS
October 27, 2023 - As you see, the value of the prototype property of the Product function (function declaration) is an empty object. In contrast, the value of the prototype property of the Productf function (arrow function) is undefined.