1
$('#title').keyup( () => {
    const title_val = $(this).val();
    console.log('before');
    if (title_val.length >= 20){
        console.log(title_val);
    }
    console.log('after');
});

console.log('before') and console.log('after') works. If-statement only works if I use function() instead of () => {...}, even if the condition is satisfied. Why does it behave like this?

roocs
  • 43
  • 1
  • 9

1 Answers1

1

There is no this operator in arrow functions, only in function functions..

when using this in an arrow function, it doesn't refer to the function scope; rather, to the parent scope (usually window)