JavaScrip and Java are essentially unrelated. In terms of historical sources, they still have a certain origin. In fact, JavaScript was called LiveScript in its early days. At that time, Java was already very popular, so LiveScript was renamed Javascr
Operating environment for this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.
1. Overview of JavaScript
What is the relationship between JavaScript and Java?
What surprises me is that essentially they have nothing to do with each other.
I can’t believe it, then why do you look so similar?
As far as historical sources are concerned, they still have a certain origin. In fact, JavaScript was called LiveScript in its early days.
At that time, Java was already very popular, so LiveScript was renamed Javascript.
To put it bluntly, isn’t this a typical hot spot nowadays?
Many Java programmers want to learn a scripting language. When they see how it is so similar to Java, they feel very familiar with it, so they might as well learn it.
JavaScrip has taken advantage of Java's hot spots, which has greatly helped its development. Of course, its language itself is also excellent, and it has slowly been recognized by the public.
It has always been at the top of the programming language rankings. When it comes to front-end Javascript, it is also an unavoidable hurdle.
I learned HTML a few days ago. If I say:
The main function of HTML is to create the structure of a web page.
The main function of CSS is to beautify the page.
Then the main role of JavaScript is to interact with users.
What is the difference between JavaScript and Java?
- Java is a compiled language that generates bytecode files before running.
- JavaScript is an interpreted language and does not generate intermediate files.
- Java requires a Jvm virtual machine to run.
- JavaScript can basically run as long as there is a browser.
But the comment formats of js and Java are exactly the same. Next, we will study the syntax of js carefully.
2. JavaScript syntax
1 Introduction of JavaScript
The introduction method is very similar to CSS. CSS is the style tag, and js is the script tag.
①Introduce
internally to write js code directly in the HTML file, and its representative tag is the script tag.
Just write the corresponding js syntax in the tag.
There can be multiple script tags in one HTML file.
②External introduction
Create a special js file externally, and the JavaScript code is written in it.
If necessary, just use the src attribute in the script tag to introduce it in the HTML file.
<script>The tag has two attributes: src and type: </script>
- src: the address of the external js file that needs to be imported. Once the js file is imported, the tag body The js code becomes invalid.
- type: Specify the type of script, fixed writing method: text/javaScript
The script tag can be placed anywhere in the HTML file, but it is generally placed in the head tag.
2JavaScript specification
The loading order of js is from top to bottom.
① Regarding the writing of semicolons
The semicolon after each sentence in js can be omitted, but for the sake of standardization, it is generally None will be omitted, just like in Java.
Because if there are several sentences in a line, compilation without semicolon will report an error.
The prerequisite for omitting the semicolon must be that one sentence occupies one line.
②About syntax error reporting
The syntax error in js can still be executed. This is different from Java. Java cannot run if an error is reported during compilation.
And what’s even more interesting is that the <script> tags are independent of each other. </script>
That is to say, there is a problem with the first <script> tag, but there is no problem with the second <script> tag. Then the code in the second tag will execute normally after running. </script>
Is this okay?
3JavaScript variable
The variable data type of js is a weak type. What is a weak type?
There are types, but the type is not emphasized. Specifically, the code is used to explainFive primitive data types:
Variables in js It is particularly interesting that the definitions are modified with the var keyword, which is the abbreviation of variate (variable).
And the var keyword is not necessary and can be omitted, but it is not recommended to omit it for the sake of standardization.
But it has a type. typeof (variable name) can determine the data type of the specified variable.
①number type
Variable a is defined as 100. It does not indicate what type it is, but its type is number type.
If it is in Java, it needs to be defined like this: number a=100;
But in js, you only need to remember the var keyword.
And what’s even more amazing is that variable a can keep changing its data type, which is simply unimaginable in Java.
②boolean type
In ①, a is still a number type, and in ②, it can be redefined as a boolean type.
③string type
The string type contains strings and characters.
The operations between strings are also spliced together, which is the same as in Java.
④null type
The null type is an object type, and the object type without assignment is a null type.
⑤undefined type
Uninitialized type, I don’t know what type it is.
This variable has not been named yet, so variable b is used in the above picture because a has been assigned a value.
The data types in Java include basic data types and reference data types, and there are also reference data types in js.
Everything in Java is an object, and Object can represent all objects.
Objects in js are also Objects. Their use is very similar to the way objects are created in Java, but there are differences.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of Is there any relationship between javascript and java?. For more information, please follow other related articles on the PHP Chinese website!

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)
