There are <select> c id = 'adresses'
When I load the page, I try to output to the console everything that exists in select using jquery with this construction

 $('#adresses option').each( function() { console.log(this.text); }); 

And everything is displayed in the console.
But if I use this design

 $('#adresses option').each( ()=> { console.log(this.text); }); 

Thousands of undefined

What is the difference?

1 answer 1

You are now being redirected, duplicating your question, but the question will remain unresolved. By simple:

In the first case, this will refer to one of the $('#adresses option') elements, so it has the property .text

In the second case, this will most likely refer to the window object, which has no .text properties (just as if you called inside the window.text function), so undefined

When you briefly write a function ()=> {} , this inside a function will not refer to this function, but will relate to the context above, in your case, to the window object

  • On learn.javascript.ru/es-function beautifully written. Внутри функций-стрелок – тот же this, что и снаружи - OotzlyGootzly
  • About this, just in the second link in the comments under the answer is painted - Grundy