What does it mean that JavaScript is “dynamic”?

前端 未结 2 970
执念已碎
执念已碎 2021-02-04 00:49

I\'ve read from different sources (e.g. wiki, articles, etc.) what dynamic in a programming sense means. Wikipedia talks about how dynamic programming languages execute certain

相关标签:
2条回答
  • 2021-02-04 01:02

    The most meaningful well-defined way in which JS is dynamic is that it's dynamically typed: the language has data types, but does not check that a program's types are "okay" until the program is actually running. The opposite is statically typed, meaning that programs' types are verified by a program that inspects their source code before they are run. (E.g., Java and ML are statically typed.)

    0 讨论(0)
  • 2021-02-04 01:24

    Most languages have some aspect of dynamic behaviour. Even statically typed languages can have a dynamic or variant data type that can contain different data types.

    JavaScript is called a dynamic language because it doesn't just have a few dynamic aspects, pretty much everything is dynamic.

    All variables are dynamic (both in type and existance), and even the code is dynamic. You can create new variables at runtime, and the type of variables is determined at runtime. You can create new functions at any time, or replace existing functions. When used in a browser, code is added when more script files are loaded, and you can load more files any time you like.

    Nowadays JavaScript is compiled in many implementations, and static code and static types are generated in the background. However, the behaviour is still dynamic, the compiler only generates static types when it finds that the dynamic aspects are not used for a specific object.

    0 讨论(0)
提交回复
热议问题