This article has participated in the third “topic writing” track of the Denver Creators Training Camp. For details, check out: Digg Project | Creators Training Camp third is ongoing, “write” to make a personal impact.

First, programming language

1.1, programming,

Programming is essentially the process of getting a computer to use a programming language to write code to solve a problem and get the result.

The computer program is a series of instructions set executed by the computer, and the program is all written with the language we have mastered, so people must control the computer through the computer language to the computer to issue commands.

1.2. Computer languages

Computer language refers to the language used for communication between people and computers, which is the medium for transmitting information between people and computers. There are many kinds of computer languages, which can be divided into three categories: machine language, assembly language and high-level language. In fact, what computers ultimately execute is machine language, the binary numbers of zeros and ones that form the basis of computer language.

1.3. Programming languages

Computers can be controlled and made to do things for us by “languages” that are similar to human languages. These languages are called Programming languages. A programming language is a set of instructions used to control a computer. It has a fixed format and vocabulary (different programming languages have different formats and vocabulary) that must be followed. Today’s common programming languages come in two forms: assembly language and high-level language.

1.4. Compilers

Programs written by high-level languages cannot be recognized directly by computers and must be transformed to be executed. For this, we need a translator. A translator converts the source code we write into machine language, also known as binarization.

1.5. Differences between programming languages and markup languages

language instructions
A programming language Programming languages have strong logical and behavioral capabilities. In a programming language, you’ll see a lot of if else, for, while instructions that are logical and behavioral. They’re active.
Markup language Markup language (HTML) is not used to issue instructions to computers, but is often used for formatting and linking. Markup languages exist to be read, they are passive.

2. Computer fundamentals

2.1. Computer Composition

2.2. Data storage

A computer internally uses binary zeros and ones to represent data. All data, including files, pictures, etc., are eventually stored on the hard disk as binary data (zeros and ones). All programs, including operating systems, are essentially data of various kinds, also stored on hard disk in the form of binary data. When we install software, we actually copy the program files to the hard disk. The hard disk and memory are binary data.

2.3 Program operation process

The process by which a computer runs software:

  1. To open a program, load the program’s code from the hard disk into memory
  2. CPU executes code in memory Note: One important reason to use memory is because cpus run so fast that reading data only from disk wastes CPU performance, so use faster access memory to store runtime data. (Memory is electricity, hard disk is mechanical)

Learning JavaScript for the first time

3.1. What is JavaScript

JavaScript is one of the most popular languages in the world. It is aScript language that runs on the client side (Script means Script). Script language does not need to be compiled, but is interpreted and executed line by line by JS interpreter (JS engine) during the running process. Server-side programming is now also possible based on Node.js technology.

3.2. What JavaScript does

  • Form dynamic validation (password strength detection) (the original purpose of JS creation)
  • Web page special effects
  • Server-side development (Node.js)
  • Desktop Program (Electron)
  • App(Cordova)
  • Control Hardware – Internet of Things (Ruff)
  • Game Development (Cocos2D-JS)

3.3, HTML/CSS/JS relationship

3.4. The browser executes JS

The browser is split into two parts:

  1. Rendering engine: Used to parse HTML and CSS, commonly known as the kernel, such as Chrome blink.

  2. JS engine: Also known as the JS interpreter, it reads JavaScript code from a web page, processes it and runs it, such as Chrome’s V8.

The browser itself does not execute JS code, but rather uses a built-in JavaScript engine (interpreter) to execute JS code. The JS engine interprets each line of source code line by line (translated into machine language) and then executes it by computer, so JavaScript is classified as a scripting language that interprets execution line by line.

3.5. Composition of JS

3.5.1 track of ECMAScript,

ECMAScript is a programming language standardized by ECMA International (formerly the European Computer Manufacturers Association). The language is widely used on the World Wide Web. It is often referred to as JavaScript or JScript, but the latter two are actually implementations and extensions of ECMAScript.

ECMAScript defines the programming syntax and basic core knowledge of JS. It is an industry standard of JS syntax that all browser manufacturers comply with.

3.5.2, DOM

DocumentObject Model (DOM) is a standard programming interface recommended by W3C to deal with extensible markup language. The DOM provides interfaces to manipulate various elements on the page (size, position, color, and so on)

3.5.3, BOM

The Browser Object Model (BOM) refers to the Browser Object Model, which provides a content-independent Object structure that can interact with the Browser window. The BOM allows you to operate browser Windows, such as pop-up boxes, control browser hops, and obtain resolution.

3.6. Introduction of JavaScript

There are three ways to import JavaScript: inline, inline, and external.

3.6.1 inline

<input type="button" value="Click on me and try." onclick="alert('Hello World')" />
Copy the code

You can write a single line or a small amount of JavaScript code inside the event attributes of an HTML tag (attributes that start with on), such as onclick(). Note the use of single and double quotes, which is recommended in HTML, and single quotes, which is recommended in JavaScript. The downside of this inline expression is obvious, and we use it only in special cases:

  1. Poor readability, in HTML to write a large number of JS code, not easy to read.
  2. Quotation marks are error-prone. When quotation marks are nested in multiple layers, they are easily confused.

3.6.2. Inline

Multiple lines of JS code can be written into script tags. Embedded JS is a common way to learn.

<script>
    alert('Hello  World~!');
</script>
Copy the code

3.6.3. External JS files

It is conducive to HTML page code structure, and separates large sections of JS code from THE HTML page, which is both beautiful and convenient for file level reuse. No code can be written in the middle of a script tag referencing an external JS file. This applies to situations where there is a large amount of JS code.

<script src="my.js"></script>
Copy the code

3.7. JavaScript comments

To improve code readability, JS, like CSS, also provides comments. There are two main types of comments in JavaScript:

  1. Single-line comments
  2. Multiline comment

3.7.1. Single-line comments

Single-line comments are commented as follows:

// I am a line of text, do not want to be executed by the JS engine, so comment it up
Copy the code

3.7.2 Multi-line comments

Multi-line comments can be commented as follows:

/* Get the user's age and name and display it in the prompt box */
Copy the code

3.8. JavaScript INPUT and output statements

In order to facilitate the input and output of information, JS provides some input and output statements, which are commonly used in three ways, among which the first two are the most common:

methods instructions attribution
alert(msg) A warning dialog box is displayed The browser
console.log(msg) The browser console prints the output The browser
prompt(info) The browser displays a dialog box for users to enter information The browser

Alert () is mainly used to display messages to the user, and nsole.log() is used to show the programmer himself runtime messages.