JavaScript use (1)

JavaScript introduction

JavaScript ("JS" for short) is a lightweight, interpreted or just-in-time compiled programming language with function first. Although it is famous as a scripting language for developing Web pages, it is also used in many non-browser environments. JavaScript is based on prototype programming, a multi-paradigm dynamic scripting language, and supports object-oriented, imperative and declarative (such as Functional programming) style. JavaScript has nothing to do with Java.

JavaScript was first designed and implemented on Netscape Navigator browser by Brendan Eich of Netscape in 1995. Because Netscape cooperated with Sun, Netscape management wanted it to look like Java, so it was named JavaScript. But in fact, its grammatical style is closer to Self and Scheme.

The JavaScript standard is ECMAScript. As of 2012, all browsers fully support ECMAScript 5.1, and older browsers support at least the ECMAScript 3 standard. On June 17, 2015, ECMA International released the sixth edition of ECMAScript. The official name is ECMAScript 2015, but it is usually called ECMAScript 6 or ES2015.

The role of JavaScript

1. Embed dynamic text in HTML page.
2. Respond to browser events.
3. Read and write HTML elements.
4. Verify the data before it is submitted to the server.
5. Detect the browser information of the visitor. Control cookies, including creation and modification, etc.
6. Server-side programming based on Node.js technology.

Features of JavaScript language

(1) Script language. JavaScript is an interpreted scripting language. Languages ​​such as C and C++ are compiled and then executed. JavaScript is interpreted line by line during the running of the program.

(2) Based on objects. JavaScript is an object-based scripting language. It can not only create objects, but also use existing objects.

(3) Simple. What JavaScript language adopts is the variable type of weak type, does not make strict requirement to the data type used, it is a script language based on Java basic sentence and control, its design is simple and compact.

(4) Dynamic. JavaScript is an event-driven scripting language that can respond to user input without going through the Web server. When visiting a webpage, the mouse clicks or moves up and down, and moves the window in the webpage. JavaScript can directly respond to these events.

(5) Cross-platform. The JavaScript scripting language does not depend on the operating system, only the support of the browser. Therefore, a JavaScript script can be used on any machine after being written, provided that the browser on the machine supports the JavaScript scripting language, and JavaScript has been supported by most browsers.

[6] Unlike server-side scripting languages, such as PHP and ASP, JavaScript is mainly used as a client-side scripting language to run on the user's browser and does not require server support. Therefore, in the early days, programmers favored JavaScript to reduce the burden on the server. At the same time, it also brought another problem, security.
As the server becomes stronger, although programmers prefer to run scripts on the server to ensure security, JavaScript is still popular due to its cross-platform and easy-to-use advantages. At the same time, some special functions (such as AJAX) must rely on JavaScript to be supported on the client side.

Where to write JavaScript code

  1. Embedded method: In the page, we can put the tag pair in the tag to write the script program:
<script type="text/javascript">
			
		</script>

text means plain text, because JavaScript is also a plain text language
PS: After entering <sc in sublime text, press the tab key to automatically complete it.

  1. External chain type: Import external JavaScript files (put them in the body tag, which can be used side-by-side with embedded js) For example: import index.js in html files

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		//引入index.js文件
		<script src="index.js" type="text/javascript" charset="utf-8"></script>
	</body>
</html>

Contents in the index.js file

alert('引入执行的index内容')

operation result
Insert picture description here

  1. Debug and run: run directly in the browser console (console is used for debugging).
    For example:
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var a = 'helloworld'
			alert(a)
			console.log(a)
			console.log(123456)
		</script>
	</body>
</html>

Page effectInsert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46384159/article/details/115159833