search
HomeWeb Front-endJS TutorialChuanzhi Podcast Learning JavaScript Basics_Basic Knowledge

1. The difference between JavaScript and java
1. JavaScript is a product of Netscape, and Java is a product of Sun.
2.JavaScript is object-based and Java is object-oriented.
3. JavaScript only needs to be interpreted before it can be executed. Java needs to be compiled into a bytecode file first and then executed.
4.JavaScript is weakly typed and Java is strongly typed.
Summary: In fact, java and JavaScript have almost nothing to do with each other except that their names are similar, and JavaScript borrows some ideas from java.
2. How to combine JavaScript with Html
1. Tag form
We store JavaScript code in the tag pair <script>. . . </script>. Can be placed anywhere.
2. Import method
Use the src attribute of the script tag to import a JavaScript file.
For example:
Note: The type attribute must be added to the script tag in the specification.
3. JavaScript syntax
1. Variables
are defined by the keyword var. Since it is a weak type, there is no need to specify a specific data type.
Example: var x = 3;
2) The special constant value in JavaScript: undefined. When a variable is used without initialization, the value of the variable is undefined.
2. Operators
Like other programming languages, similar to java. It also supports the string concatenation operator ( ) and the ternary operator (? :). The difference is that the ternary operator does not need to have a value and can be directly output in the statement.
3. Statement
The statement format is similar to that of various programming languages, and there are also judgments, selections and loops. But pay attention to a few points:
1) Non-zero is true in JavaScript. For example, the following code
var x = 3;
if(x==4)//can perform comparison operations.
if(x=4)//Assignment operations can be performed, and judgments can also be made. No error is reported. The result is true, so you can write if(4==x) backwards after the if statement, so if you write 4=x, an error will be reported. Mistakes can be corrected.
2) There are no type restrictions in switch
3) The loop must have an end condition
4) To connect boolean operations, you must use && or ||, if you use & or |, bit operations will be performed

4. Function
1. General function
format:
function function name (formal parameters...)
{
execution statement;
return return value;
}
Note: 1) The return statement does not need to be written, the function must be called before it will run.
2) There is no need to add var to formal parameters, which are weak types.
3) Call a function with parameters, but do not pass it a value, or pass more values ​​than the number of parameters. The function will still run. Or call a function without parameters and pass a value to it, and the function will still run. .
4) There is no overloaded function form in JavaScript
Because multiple parameters of a function are actually encapsulated in an arguments array in JavaScript, any number of parameters can be accepted, but it is best to follow the defined form Parameters pass the actual parameters.
5) Pay attention to the following example
var show = demo();
The above statement indicates that the show variable receives the return value of the demo function.
var show = demo;
The above statement means that show and demo represent the same function, pointing to the same object
2. Dynamic function
is implemented through JavaScript’s built-in object Function. As follows:
var demo = new Function("x,y","var sum = x y; alert(sum);");
demo(5,2);
Dynamic functions are different from general functions What's more, parameters and function bodies can be passed through parameters and can be specified dynamically.

3. Anonymous function
Format: function()
Example: var demo = function(){alert("snow");}
demo();
Note: Usually used when defining the behavior of event properties.
4. Other forms
var p = new Object();
p.name ="lisi";
p.age=31;
p.demo = show;
alert(p.name ":" p.age demo(4,5));
function show(x,y){return x y;}

5. Array in In JavaScript, arrays combine the characteristics of collections and can store any elements, and the length is also variable. And when assigning values, there are not braces but square brackets, as follows:
var arr = new Array();
arr[0] = "ashf";
arr[1] = 258;
Or var arr = ["ashf",258,true,'sfa'];
Be careful not to use int x when traversing, but var x, which is a weak type.
Two-dimensional array: var arrr = [[Element,Element....],[Element...],[Element....]....]

6. Built-in Object
In JavaScript, there are many built-in objects, such as String, Object, Date, etc. You can check the relevant help documents (if necessary, you can leave your email address). Here we will briefly explain some of the differences.
1. The length in String is an attribute, not a method
2. The substring (a, b) method in String takes the characters from a to b-1, while the substr (a, b) method starts from a and takes b characters
3.a.toString(b) returns the a form of b base
4.parseInt ("a", b) will convert the b base a into the decimal form of a


7. Custom objects
In JavaScript, in addition to the built-in objects already provided, you can also customize objects.
Method 1:
function car(){}
var c = new car();
c.color = "white";
c.tyre = 4;
c .run = show;
function show(){alert(c.color c.tyre “run”);}
c.run();
Method 2:
function car(color, tyre)
{
this.color = color;
this.tyre = tyre;
}
var c = new car(“white”,4);
alert(c .color ":" c["tyre"]);
8. Statements for operating objects
1. with statement
When calling multiple members of an object, In order to simplify the call, avoid repeated writing in the format of "object.".
Format: with (object) { There is no need to add (object.property) to the code here}
var p = new car("white",4);
alert(c.color ":" c ["tyre"]);
can be written as:
var p = new car("white",4);
with(car){alert(color ":" tyre)};
Note: The with statement defines the scope of an object, in which members of the object can be directly called.
for...in statement
For variable in object statement: traverse the members in the object, if traversing the array, the variable is the subscript
Get the value object [variable] of the object, the variable is the attribute name

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
From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript: Exploring the Versatility of a Web LanguageJavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The Evolution of JavaScript: Current Trends and Future ProspectsThe Evolution of JavaScript: Current Trends and Future ProspectsApr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Demystifying JavaScript: What It Does and Why It MattersDemystifying JavaScript: What It Does and Why It MattersApr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools