JSFiddle - React, Tailwind, and code Playground

by Roman Zhak

JavaScript

// #1:
  // global must be changed 
  window.b = 4; 
  // pass global var name here
  // It does not passed by link
  function plusOne(name) {
   var global = window;
   if( name in global 
      && typeof +global[name] == 'number' )
    window[name]++;
  }
  plusOne('b');
  console.log('var b = %d;', b); // => 5

  // #2:
  // pass as a link
  var c = {
    value: 2
  };
  function $plusOne() {
   this.value++;
  }
  $plusOne.call(c)
  console.log('var c = %d;', c.value); // => 3

  // #3:
  // if var is local
  var a = 6;
  function _plusOne(){ 
   // say its name here
   if( typeof +a == 'number' )
   a++;
  }
  _plusOne();
  console.log('var a = %d;', a); // => 7