JSFiddle - React, Tailwind, and code Playground

by Sergei Sokolov

HTML

<select id="mySelect">
      <option value="1">1</option>
      <option value="3">3</option>
      <option value="5">5</option>
    </select>
<output></output>

JavaScript

/**
 * для вопроса https://qna.habr.com/q/703614
 * Как отследить изменение значения в переменной?
 */
let selectValue = document.getElementById('mySelect').value;
let select = document.getElementById('mySelect');
const output = document.querySelector('output');

select.addEventListener('change', function (event) {
  selectValue = event.target.value;
  output.innerText = 'обновились на ' + selectValue;
});

output.innerText = 'начальное значение ' + selectValue;