Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the features of Javascript dynamic language

Shulou Source: shulou.com Published: 2022-06-03 08:10:43 09月26日 Update

This article shows you what features Javascript dynamic language has, which is concise and easy to understand, and can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

JavaScript is a dynamic, weakly typed, prototype-based scripting language. In JavaScript, "everything is an object". In this respect, it is more thorough than other OO languages. Function, even as the carrier of the code itself, is also an object, and the boundary between data and code has been quite blurred in JavaScript. Although it is widely used in WEB clients, its scope of application is far from limited to this.

What are the features of Javascript dynamic language

Dynamic means that in a Javascript object, to assign a value to an attribute, we do not need to create a field in advance, but only need to do the assignment operation when using it, as in the following example:

/ / define an object

Var obj=new Object ()

/ / dynamically create attribute name

Obj.name= "an object"

/ / dynamically create attribute sayHi

Obj.sayHi=function () {

Return "Hi"

}

Obj.sayHi ()

Join us in using the Java language, and the code might look like this:

Class Obj {

String name

Function sayHi

Public Obj (Sting name,Function sayHi) {

This.name=name

This.sayHi=sayHi

}

}

Obj obj=new Obj ("an object", new Function ())

Dynamics are very useful, which we will explain in more detail in later chapters.

Javascript weak class type characteristics

Unlike Java,C/C++, Javascript is weakly typed, its data type does not need to be specified at declaration time, and the interpreter instantiates variables based on context, such as:

/ / define a variable s and assign it to a string

Var s = "text"

Print (s)

/ / assign s to be integer

Slug 125,

Print (s)

/ / assign s to floating point

Sworn 6.3

Print (s)

/ / assign s to an object

S=new Object ()

S.name = "object"

Print (s.name)

The result is:

Text

seventeen

6.3

Object

As you can see, the variable of Javascript is more like a container, similar to the top-level object Object in the Java language. It can be of any type, and the interpreter automatically shapes it according to the context.

The advantage of weak typing is that a variable can be reused to a large extent, such as the name field of type String, which, after being used, can be assigned to another Numbertype object without having to recreate a new variable.

However, weak typing also has its downside, for example, when developing object-oriented Javascript, it will be troublesome to have no type judgment, but we can solve this problem in other ways.

What are the interpretations and compilations of Javascript

Generally speaking, Javascript is an interpreted language, especially in Javascript in browsers, where all major browsers parse Javascript as an interpreted script. However, this is not a rule. In the Java version of Javascript interpreter rhino, scripts can be compiled into Java bytecode.

Interpretive language has certain advantages, that is, it can modify the code at any time, no need to compile, refresh the page and reinterpret, and you can see the results of the program in real time, but because it needs to be explained each time, the cost of the program is high; on the other hand, the compiled language only needs to be compiled once, and the compiled code can be run every time, but it loses its dynamics.

What are the features of Javascript dynamic language? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Language dynamic type interpretation object code variable compilation property dynamic property script interpreter up and down context content benefit field skill data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi macOS vpn Linux