Should an import statement be placed before or after the "use strict" line?

Hello,
I have a situation where I need to import a JavaScript file, but the file also has a 'use strict' line. I was wondering whether the import should come first, or if 'use strict' should be the first line. I looked this up on Google but couldn’t find any examples.

import AnchorJS from './anchor'; <--- this

"use strict";  <--- and this

// Menu
const menuToggleBtn = document.querySelector(".menu-toggle");
menuToggleBtn.addEventListener("click", event => {
  event.preventDefault();
  menuToggleBtn.parentElement.classList.toggle("open");
});

document.addEventListener('DOMContentLoaded', () => {
  const anchors = new AnchorJS();
  anchors.add('.blog-post h3');
  anchors.add('.blog-post h4');
  anchors.add('.blog-post h5');
  anchors.add('.blog-post h6');
});

Hi @zoltankr, you don’t need “use strict” here at all as JS modules are always in strict mode anyway. :-)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.