JSFiddle - React, Tailwind, and code Playground
HTML
<input type="number" /> <button>hogeの中身</button>
<div></div>
JavaScript
var hoge = 0;
var print;
$(function(){
print = function(text){
$('div').html($('div').html() + text + '<br />');
};
});
$(function(){
$('input').on('change',function(e){
var d = Number(e.target.value);
hoge += d ? d : 0;
print('ここじゃない!の場所 : ' + hoge);
})
print('ここのグローバル変数を加算していきたい!の場所 : ' + hoge);
});
$(function(){
$('button').click(function(){
print('ちゃんとグローバルに保存されている : ' + hoge);
});
});