29

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?

OpMt
  • 1,723
  • 4
  • 19
  • 24
  • 1
    I think the word dynamic could refer to different concepts depending on the context so I guess you should provide the source you are referring to, and we could try to figure out what dynamic meant in *that* context. – Andrea Casaccia Sep 09 '15 at 10:09
  • 3
    Just drill down the link you supplied and it explains the ways in which they refer to Javascript as *dynamic*... https://en.wikipedia.org/wiki/JavaScript#Dynamic – Reinstate Monica Cellio Sep 09 '15 at 10:15
  • 1
    @Archer but like specifically for what happens at runtime for Javascript is what I'm also curious about – OpMt Sep 09 '15 at 10:18
  • 1
    @AndreaCasaccia I link to the wiki article in my post, and googling is helpful for a bunch of other random ones XD – OpMt Sep 09 '15 at 10:19
  • 2
    Javscript can be modified after running. For example, a button click can load more script, or modify (override) an existing function. You can also modify object structures at will. Also, nothing is strongly typed which means you can manipulate almost everything, at runtime. If you have a specific question about something you want to do then you should be looking into that. I don't think you quite grasp the vastness (and vagueness) of the question you've posted. – Reinstate Monica Cellio Sep 09 '15 at 10:20
  • 1
    I'm just trying to get more information in general but also into the details. Do you know the details of how it varies in complexity and performance costs? I'm even curious on the numbers are compared to other programming languages XD – OpMt Sep 09 '15 at 10:22
  • 1
    I did but was not able to find the specifics and was curious if anyone on here knows the source to these details or knows in general. – OpMt Sep 09 '15 at 10:27
  • You need to ask a specific question. What you'r asking has so far made no sense. Sorry - I can't help if you can't explain. – Reinstate Monica Cellio Sep 09 '15 at 10:31
  • 1
    you obviously don't know/can't comprehend. lol. – OpMt Sep 09 '15 at 10:34
  • @OpMt in stackoverflow we can't make a monographic. This is to solve problems. You are searching for a extensive explanation, and this is not the place. The best you can do is start programming in javascript and compare how to make in another languages. However, javascript is unique, I don't know what do you need to compare how languageS – Marcos Pérez Gude Sep 09 '15 at 10:48
  • 1
    @MarcosPérezGude I agree that stackoverflow can't make a 'monographic' and that is perfect for this question and is the root of where it came from. Stackoverflow allows engineers/programmers/developers to come together and allows us all to have a discussion and share knowledge on relevant topics. That is the purpose of this question. – OpMt Sep 09 '15 at 10:52
  • Good appointment. So I try to tell you that the most information about *dynamic* development with javascript is what you see. Performance, comparatives, etc, you must to make some work also :) Have a nice day and good luck in your search! – Marcos Pérez Gude Sep 09 '15 at 10:54

2 Answers2

35

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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • 1
    For sure I read up from different articles a lot of what you wrote. +1 for actually being constructive. So it seems like there is no fine line/straight answer on what dynamic is meant specifically for JavaScript. – OpMt Sep 09 '15 at 10:47
  • A bit of context: A software engineer at a top tech company asked me directly how JavaScript is dynamic, looking more for a straight answer. – OpMt Sep 09 '15 at 10:54
  • 1
    @OpMt: Exactly, there is no precise rule. It's called a dynamic language basically because it was intended to be one, and that is seen by the choises in the language design. – Guffa Sep 09 '15 at 11:10
  • Also, objects are dynamic. `eval` is very dynamic. And most of all, inheritance is dynamic. – Bergi Sep 09 '15 at 13:34
4

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

liban
  • 41
  • 2