Alternating attributes without values

Let a disabled input and a button be given:

html<input id="elem" disabled>
<input id="button" type="submit">

Let's make it so that each click on the button causes the input to change its state - from disabled to enabled and vice versa. First, let's get references to our elements into variables:

javascriptlet elem   = document.querySelector('#elem');
let button = document.querySelector('#button');

Now let's implement what we've planned:

javascriptbutton.addEventListener('click', function() {
  if (elem.disabled) {
    elem.disabled = false;
  } else {
    elem.disabled = true;
  }
});

The problem, however, can be solved with less code:

javascriptbutton.addEventListener('click', function() {
  elem.disabled = !elem.disabled;
});
Задание 1

Explain how the above code works.

Задание 2

Given a checkbox and a button. Make sure that each button click causes the checkbox to change its state.