Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean that JavaScript is "dynamic"?

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 programming behaviors at runtime (as opposed to compile time for static languages), but their explanation is vague and talks about how these behaviors vary in degree of difficulty, complexity, and performance costs for all programming languages.

So with respect to JavaScript specifically, what does it mean that it's dynamic?

I may be completely wrong on this, but also understand JavaScript to be a dynamically typed language since you don't have state the type before instantiating a variable/function(e.g. var, function jsFunction()) as opposed to a statically typed language like Java where you define a type before instantiating a variable/function(e.g. int var, public int function()).

Does this have to do with any of this?

like image 344
OpMt Avatar asked Sep 09 '15 10:09

OpMt


People also ask

What does it mean that JS is dynamic?

JavaScript is a dynamically typed language It means that JS does not require the explicit declaration of the variables before they're used.

What is dynamic and static in JavaScript?

The differences between static type checking and dynamic type checking matter most when a type error occurs. In a statically-typed language, type errors occur during the compilation step, that is, at compile time. In dynamically-typed languages, the errors occur only once the program is executed. That is, at runtime.

What JavaScript does to make things dynamic?

In JavaScript, you can choose dynamic values or variable names and object names and choose to edit the variable name in the future without accessing the array. To do, so you can create a variable and assign it a particular value.

What does it mean that JavaScript is loosely typed and dynamic?

JavaScript is a loosely typed language, meaning you don't have to specify what type of information will be stored in a variable in advance. JavaScript automatically types a variable based on what kind of information you assign to it (e.g., that '' or " " to indicate string values).


2 Answers

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.

like image 164
Guffa Avatar answered Sep 29 '22 03:09

Guffa


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.)

like image 31
liban Avatar answered Sep 29 '22 02:09

liban