How to use local in object and global variable with this and function in JavaScript

1 Answer

0 votes
var obj = {s: 'Local'};

var s = 'Global';

function f() {
  return this.s;  
}

console.log(f());          

console.log(f.call(obj));  

console.log(f.apply(obj)); 




/*
run:

Global
Local
Local

*/

 



answered Nov 20, 2020 by avibootz
...