Home  >  Article  >  Web Front-end  >  Share some selected web front-end interview questions worth collecting (with answers)

Share some selected web front-end interview questions worth collecting (with answers)

青灯夜游
青灯夜游forward
2022-07-07 10:36:032132browse

This article summarizes some selected Web front-end interview questions worth collecting (with answers). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Share some selected web front-end interview questions worth collecting (with answers)

js interview questions

  • 1.js data type

    • Basic data types
      Number, String, Boolean, Null, Undefined, Symbol, bigInt
    • Reference data types
      object, Array, Date, Function, RegExp
  • 2. Promotion of js variable and function declarations

    • The declaration of variables and functions in js will be promoted to the top to execute the
    • function The promotion is higher than the promotion of variables
    • If an external variable with the same name is declared using var inside the function, the function will no longer search upward.
    • Anonymous functions are not promoted.
  • 3. Closure

    • A closure is a function that can read the internal variables of other functions
    • Basically, a closure It is a function that returns a function inside.
    • Benefits
      • You can read the variables inside the function
      • Keep the variables in the memory all the time
      • You can encapsulate objects Private properties and private methods
    • Disadvantages
      • It consumes more memory and may cause memory overflow if used improperly
  • 4. The difference between == and ===

    • == is equality in a non-strict sense
      • Equal values ​​are equal
    • === is equality in the strict sense, and will compare the data types and value sizes of both sides
      • Equal only when the value and reference address are equal
  • 5. this

    • this always points to the direct caller of the function
    • If there is a new keyword, this points to the object from new
    • In the event, this points to the object that triggered the event
  • 6. How to traverse js arrays and objects

    • for in
    • for
    • forEach
    • for-of
  • ##7. The difference between map and forEach

      The forEach method is the most basic method, which is traversal and looping. There are three parameters passed by default: the content of the traversed array
    • , the array index index, and the current traversed array Array
    • map method, the basic usage is the same as forEach, but different, it will return a new array, so callback
    • needs to have a return value, if not, it will return undefined
  • 8. What is the difference between arrow functions and ordinary functions?

      The this object in the function body is the object where it is defined, not the object where it is used
    • It cannot be used as a constructor, that is, the new command cannot be used, otherwise an error will be thrown
    • The arguments object cannot be used, and the object does not exist in the function body. If you want to use it, you can use the Rest parameter instead
    • The yield command cannot be used, so the arrow function cannot be used as the Generator function
  • 9. Same-origin policy

      The same origin refers to the same domain name, protocol, and port number
  • 10. How to solve cross-domain issues

      jsonp cross-domain
    • document.domain iframe cross-domain
    • nodejs middleware proxy cross-domain
    • The backend sets the secure domain name in the header information
  • 11. Restrictions of strict mode

      Variables must be declared before use
    • The parameters of the function cannot have the same attribute, otherwise an error will be reported
    • Cannot use the with statement
    • Prohibit this from pointing to the global object
  • 12, es6 new addition

      New template string
    • Arrow function
    • for-of (used to traverse data—such as values ​​in an array.)
    • ES6 incorporates Promise objects into the specification and provides native Promise objects.
    • Added let and const commands for declaring variables.
    • There is also the introduction of the concept of module module
  • 13. What is the difference between attribute and property?

      Attribute is The properties
    • property that the dom element has as an html tag in the document are the properties that the dom element has as an object in js.
    • For the standard attributes of html, attribute and property are synchronized and will be updated automatically
    • But for custom attributes, they are not synchronized
  • 14. What is the difference between let and const?

      The let command does not have variable promotion. If used before let, an error will be reported
    • If there are let and const commands in the block area, a closed scope will be formed
    • Repeated declarations are not allowed
    • const defines a constant and cannot be modified, but if it defines an object, The data inside the object can be modified
  • 15. Memory leak

      Definition: The heap memory that has been dynamically allocated in the program has not been allocated for some reason. Various problems caused by release or inability to release.
    • Possible memory leaks in js: Result: slowdown, crash, large delay, etc.
    • Possible causes of memory leaks in js
      • Global variables
      • When the dom is cleared, there are still references
      • The timer is not cleared
      • Memory leak caused by the existence of sub-elements
  • 16. How to introduce script?

    • html static<script> introduction</script>
    • js dynamic insertion<script></script>
    • ##