-6

Let in c when we declare a variable we have to specify the type of that variable like:

int a; but in scripting language (php, javaScript, ruby), we don't specify the type of variable. we just declare the variable like: $a=12; $b='123'; $name = ['vijay', 'jon', 'david'];

WHY TYPE IS NOT DEFINED BEFORE DECLARING THE VARIABLE IN SCRIPTING LANGUAGE ?

vijay
  • 11
  • 5

4 Answers4

2

Because the variable itself holds its own type, as well as its value.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • HI Evert, could you please explain How ? – vijay Dec 27 '14 at 16:00
  • Well, every scripting language engine would do that different. You can look in the source of for example php or python and see how their respective variable structures are stored. – Evert Dec 27 '14 at 16:38
0

Some languages are strictly typed, like c. Some are not, like PHP, JavaScript, etc. This is just a design choice by the language developer of a given language.

As Evert pointed out, in languages without strict typing, the variable itself stores information about its type.

elixenide
  • 44,308
  • 16
  • 74
  • 100
0

JavaScript is a dynamic programming languges, which means you do not declare the data types of variables explicitly. In many cases JavaScript performs conversions automatically when they are needed. For example, if you add a number to an item that consists of text (a string), the number is converted to text.

Also follow this link

And also this

Priyank
  • 3,778
  • 3
  • 29
  • 48
0

Scripting languages are not dynamically typed.
Dynamic typing is language feature, that comes from language developers and it's their decision.

Also, dynamically typed laguange doesn't imply only dynamic declaring variable, but also it allows to change variable type during variable lifespan.

Here is topic about dynamic and static typed languages: dynamic/static

To understand how dynamic and static languages work under the hood, I suggest lecture of good book (probably a few), not only internet, as its biiig amount of knowledge to aquire :).

Community
  • 1
  • 1
Jarema
  • 3,291
  • 2
  • 17
  • 30