Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 5
    The var name = "Ali" style is actually common for modern statically typed languages. In statically typed languages, the type is fixed at creation, but it still can be determined by the initializer. The definition of a dynamically typed language is that types attach to values, not variables. Assigning a value to a variable therefore sets the variables's type as well. Commented Mar 20, 2016 at 23:31
  • @MSalters: I made a slight adjustment to the wording. Commented Mar 20, 2016 at 23:35
  • 5
    The irony here is this includes C# with this exact syntax. Commented Mar 21, 2016 at 1:34
  • 1
    @MSalters Assigning a value to a variable therefore sets the variables's type as well. Or that the variable has no inherent type and the interpreter will attempt to apply whatever operation to the value of the variable. Are there any dynamically typed languages where code like the following (Javascript) would not be allowed var x = 5; x = ""; because the first statement causes x to have the "Number" type associated with x? Sort of conflicts with dynamic typing. And if not, what effect does the type associated with the variable have, beyond the type association with the value? Commented Mar 21, 2016 at 9:35
  • 1
    @ZevSpitz: The first kind of system isn't dynamically typed, but not typed at all. Your Javascript example isn't dynamically typed, precisely because the Number type cannot change. In a dynamically typed language, x = ""; changes the type of x to string, even if it was a number previously. Commented Mar 21, 2016 at 12:40