Questions tagged [arrow-functions]

Questions about the compact function syntax in ECMAScript2015 (ES6) called "arrow functions" because of their use of "=>".

"Arrow functions" are a compact syntax for function definitions in ECMAScript 2015 (ES6).

Arrow functions differ from regular functions in several ways:

  • They cannot be named. They are anonymous only.
  • They are not constructors, don't have a .prototype and cannot be instantiated by new.
  • They use lexically scoped this instead of binding this dynamically on the call

Arrow functions are also available in CoffeeScript.

1520 questions
-2
votes
2 answers

ES6 Arrow function to normal JS conversion

I am having hard time writing the below line in normal JS Syntax as IE doesn't support ES6 JavaScript. Updating the question. My Input is as follows. var onlyData = [ ["Individual Id","Individual Last Name","Individual First Name","Individual…
Jyotirmaya Prusty
  • 278
  • 1
  • 8
  • 25
-2
votes
1 answer

Using if...else... in Arrow Function

I use the ajax to get information in Vue.js, so my code is: fetch('http://work1999.kcg.gov.tw/open1999/ServiceRequestsQuery.asmx/ServiceRequestsQuery').then(function (response) { if (response.ok) { return response.json(); } else { …
Mark
  • 27
  • 1
  • 9
-2
votes
1 answer

How to using ES6 Arrow function to realize Immediately-Invoked Function Expression (IIFE))?

How to using ES6 Arrow function to realize IIFEImmediately-Invoked Function Expression? Here is my demo codes, and it had tested passed! // ES 6 + IIFE (() => { let b = false; console.log(`b === ${b}!`); const print = `print()`; …
-2
votes
1 answer

What are ES6 arrow functions, how do they work?

I am curious about ES6 arrow functions (fat arrow functions). Are they simply syntactic sugar derived from CoffeeScript, or is there more to them than meets the eye?
Adrian Oprea
  • 2,360
  • 3
  • 21
  • 23
-3
votes
0 answers

What's the difference in Arrow Function in these 2 cases?

This one is working fine but the other one isn't showing the output on UI Why it isn't running with {} brackets? syntax of arrow functions is () => {} but it isn't running with this but with () => ()
-3
votes
2 answers

How can i make this JS code simpler help! Too much if statements

Im a rookie in coding, an im figuring a way to shorten this code, it has too many if statements, if someone can help me out, i really apreciatted. I need to add a classList.remove to the same elements too after that So this is the code: const…
John99
  • 13
  • 1
-3
votes
3 answers

Why do I get an error when I write a traditional function as an arrow function?

I wrote a very simple addition function. The first code was written with the traditional function. But I want to write the same code with arrow function, but a red error appears under the arrow sign and when I want to see the result with…
Mirza
  • 17
  • 4
-3
votes
2 answers

How to change this code to normal function?

Hello everyone can anyone help me to convert this code by using normal function without using the arrow function.Your kind help will help me alot to accomplish my project const arrows = document.querySelectorAll(".arrow"); const movieLists =…
-3
votes
1 answer

Array.prototype.filter() expects a value to be returned at the end of function array-callback-return

I am trying handle below code and its showing enter image description here const toArray = props => (props && props.split ? props.split(',') : props || []).map(item => item.trim()); const hasField = (entity, fields) => { if (!fields.length)…
-3
votes
1 answer

can someone tell me why my js code is not printing the date using the arrow function?

const datee = () => document.write(new Date()); datee; //no response, same for console.log const datei = () => new Date(); console.log(datei); // () => new Date(); The comments above shows what they are printing if they are printing anything
-3
votes
1 answer

getting NaN when asking for video duration

Can anyone help me understand why console.log(this.getPlayerDuration()) inside of setAttendancePromptTimeLimit() is returning NaN? // video-player.js const videoP = document.querySelector('#in-course-player') class videoPlyer { …
qb1234
  • 155
  • 2
  • 14
-3
votes
3 answers

I can't understand why it returns undefined

I am trying to add 2 to given array. But the code returns undefined when run. I am trying to learn ES6, I couldn't find the problem. I need help. const mapSomething = (arr) => { arr.map(n => { return n + 2; }) } // It have to return…
-3
votes
1 answer

JavaScript arrow-function using navigator.userAgent as an example

const browser = ((agent) => { switch (true) { case agent.indexOf("edge") > -1: return "edge"; case agent.indexOf("edg") > -1: return "chromium based edge (dev or canary)"; case agent.indexOf("opr") > -1 && !!window.opr:…
user14570849
-3
votes
2 answers

How do i convert these arrow functions into regular functions to support IE?

I'm new to JavaScript and I'm not sure how to convert these two arrow functions into regular functions. If someone could convert them and give me an explanation that would be great! function getBase64(file) { try { return new…
-3
votes
1 answer

Two return statements in one arrow function

Consider the following: class VillageState { constructor(place, parcels) { this.place = place; this.parcels = parcels; } move(destination) { if (!roadGraph[this.place].includes(destination)) { return this; } else { …
Jordan
  • 194
  • 1
  • 12
1 2 3
99
100