if you meet the problem¬†Uncaught TypeError: Cannot set property ‘checked’ of null, the issue can be that the script is executed before the checkbox was part of the DOM.

the solution is to use addEventListener & DOMcontentLoaded inside your javascript

document.addEventListener("DOMContentLoaded", function() {
  document.getElementById("test").checked = true;
});