In my world it isn't. I much prefer to write my functions in the classic style.
function myFunction() {
}
async function myAsyncFunction() {
}
async function doFunction() {
await myAsyncFunction();
myFunction();
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've used javascript for years, but fairly new to the arrow functions.
Can someone tell me how this:
const getData = async () => {
//rest of code
28 spaces used to reach {
is better than this:
async function getData() {
// rest of code
25 spaces to reach {
So it sure is not shorter.
I ask because so far some of the newer shortcuts just don't make sense to me.
One of the arguments for them:
Arrow functions are often preferred in modern JavaScript code for their readability and shorter syntax
In the above the old way is very readable and shorter?
I also notice even modern Axios JS uses the old style in the example:
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
See https://axios-http.com/docs/example
I wish folks would learn:
If it ain't broke don't fix it.
In my world it isn't. I much prefer to write my functions in the classic style.
function myFunction() {
}
async function myAsyncFunction() {
}
async function doFunction() {
await myAsyncFunction();
myFunction();
}
Please or to participate in this conversation.