This keyword behaviour

function bike()
{
console.log(this.name);
console.log(this == global)
}

let name = “Ninja”;
var obj1 = { name: ‘Pulsar’, bike: bike }
var obj2 = { name: ‘Gixxer’, bike: bike }

bike()
obj1.bike()
obj2.bike()

//Output
undefined
true
Pulsar
false
Gixxer
false

//In the very first line instead of Ninja why i am getting undefined, name is a global variable and in that section this is behaving a global so why does it not pointing to it??

Name is not a global variable here. To define a global variable, instead of
let name = “Ninja”
you need to wite:
global.name = “Ninja”
After that, name will be a global variable, and this.name can be accessed in the function.

Also, see this: https://stackoverflow.com/questions/19850234/node-js-variable-declaration-and-scope