Understanding the 'this' keyword in JavaScript | CodeSketched

Поделиться
HTML-код
  • Опубликовано: 25 янв 2025

Комментарии • 2

  • @JudoboyAlex
    @JudoboyAlex 2 года назад +1

    This explicit binding example gets me undefined when I run it on code editor --> var scope ='global'; function test(){console.log(this.scope); test()
    Edit: But when I run this in chrome console then I get "global" then undefined. Why is this?

    • @CodeSketched
      @CodeSketched  2 года назад

      When you run a function in Chrome console, it prints the return value of that function by default. So one of the undefined would be the return value of your test function.