Home  >  Article  >  Web Front-end  >  Are javascript and java syntax the same?

Are javascript and java syntax the same?

青灯夜游
青灯夜游Original
2021-11-24 12:03:293116browse

Javascript syntax is different from java syntax. JavaScript is a weakly typed language. When declaring variables, there is no need to specify the type of the variable. It can be defined uniformly using the var keyword; while Java is a strongly typed language, and variables must be declared with the corresponding type.

Are javascript and java syntax the same?

The operating environment of this tutorial: windows7 system, javascript1.8.5&&java8 version, Dell G3 computer.

Javascript syntax is different from java syntax.

The difference between JavaScript and java

**特点**		**Java**					**JavaScript**
面向对象			面向对象编程语言				基于对象,不完全面向过程。有部分面向对象
											的特点
											
运行方式			编译型语言,生成中间文件,	不会生成中间文件
				字节码解释型,解释一部分,
				再运行一部分。
							
跨平台			安装虚拟机跨平台				运行在浏览器中,只要系统有浏览器就可以运行。

数据类型			强类型语言,不同的数据		弱类型,同一个变量可以赋值不同的数据类型。
				类型严格区分					
				
大小写			区分大小写					区分大小写

JavaScript is a weakly typed language. When declaring a variable, you do not need to specify the type of the variable. You can use the var keyword uniformly. to define. Java is a strongly typed language, and variables must be declared with corresponding types; for example: int and char need to be used to define variables of int type and char type respectively.

javaScript is a dynamic, weakly typed language, while java is a static, strongly typed language.

Dynamic language (weakly typed language) is a language that determines the data type at runtime. There is no need for a type declaration before a variable is used. Usually the type of the variable is the type of the value to which it is assigned.

Static language (strongly typed language) is a language in which the data type of the variable can be determined at compile time. Most statically typed languages ​​require that the data type must be declared before using the variable.

Strongly typed languages ​​may be slightly inferior to weakly typed languages ​​in terms of speed, but the rigor brought by strongly typed languages ​​can effectively avoid many errors.

For example: if you define an integer variable a, then it is impossible for the program to treat a as a string type. A strongly typed definition language is a type-safe language.

But in javaScript, because the constraints are relatively weak, some errors are prone to occur. The simplest example:

Are javascript and java syntax the same?

You may expect c to be 201, but in fact It is "2001", an error that never occurs in strongly typed languages. However, precisely because JavaScript does not have these constraints, it can easily concatenate numeric and string types.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of Are javascript and java syntax the same?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn