JSFiddle - React, Tailwind, and code Playground

JavaScript

var foo = 'global var foo';
function bar() {
    console.log('initial foo', foo);
    console.log('initial  this.foo', this.foo);

    this.foo = 'this.foo #1';
    var foo = 'new local var foo #1';

    console.log('assignment #1 foo', foo);
    console.log('assignment #1 this.foo', this.foo);
    
    var foo = function () {};
    
    console.log('assignment #2 foo', foo);
    console.log('assignment #2 this.foo', this.foo);
    return;
}

bar();
console.log('after function call foo', foo);