Is a function required in js?

  • 0
    Good afternoon!
    Does button.forEach () also need to be framed in a function or is it allowed by standards (ES6, etc.) like mine?
    Code structure:
    let button = document.querySelectorAll('masterSelector');
    let subMenuAll = document.querySelectorAll('slaveSelector');
    const dnoneStyle = () => {	
    //несколько строк кода
    button.forEach((e) => {
    //несколько строк кода
    //...... еще куча кода
    JavaScript Jase Huff, Sep 19, 2020

  • 1 Answers
  • 0
    If I understand your question correctly, it depends on the goal. Arrow functions are used to preserve the context (this), or (if it is not important) for more readable code. If you use function, the context will not be saved.

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!