Hello, today for everyone children’s shoes to share is JS, quickly take out a small notebook to write down

First Javascript

Function:

  1. Form dynamic verification (password strength detection)
  2. Web page special effects
  3. Server-side development (Node.js)
  4. Desktop Program (Electron)
  5. The App (Cordova)
  6. Control Hardware – Internet of Things (Ruff)
  7. Game Development (Cocos2D-JS)

HTML/CSS/JS

HTML/CSS Markup Language – Description class language

  1. HTML determines the structure and content of a web page, the equivalent of the human body
  2. CSS determines how a web page will look to the user, much like dressing or putting on makeup

JS scripting language – programming class language

Industrial business logic and page control (decision function), equivalent to various human actions

An introduction to browser JS execution

  1. Rendering engine: used to parse HTML and CSS, commonly known as kernel, such as Blink in Chrome, older versions of WebKit
  2. JS engine: also called JS interpreter. It is used to read Javascript code from a web page, process it and run it, such as Chrome 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 language is classified as a scripting language that performs interpretive execution

The composition of JS

ECMAScript: JavaScript syntax

DOM: Page document object model

BOM: Browser object model

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

DOM – Document Object Model (DOM) : The DOCUMENT Object Model (DOM) is a standard programming interface recommended by the W3C for dealing with extensible Markup Language (XML). DOM provides interfaces for manipulating various elements on a page (size, location, color, etc.)

BOM – Browser object model: It provides a content-independent object structure that can interact with the browser window to manipulate the browser window, such as pop-ups, controlling browser jumps, obtaining resolution, etc

At the beginning of js experience

Js has three writing positions: inline, inline, and external

Note that we recommend double quotes in HTML and single quotes in JS

Alert (‘ hymn of valor ‘);

Note: No code can be written between script tags that reference external JS files

Js annotation

Input output statement

Js variable

Overview: What are variables

In plain English: A variable is a box of things

Popular: A variable is a container for storing data, which can be retrieved by its name and even modified

Declare a variable

// Declare the variable var age; // Declare a variable named age

Var is a JS keyword used to declare variables. After the keyword is used to declare variables, the computer automatically allocates memory space for the variables

Age is the name of the variable defined by the programmer

The assignment

age = 10; // Assign the age variable to 10

= is used to assign the value on the right to the variable space on the left

A variable value is a value that the programmer saves into the variable space

Initialization of a variable

var age = 18; // declare the variable and assign it to 18

Declaring a variable and assigning a value is called initialization of the variable

Use cases for variables

  1. An input box pops up, prompting the user to enter a name
  2. A dialog box pops up with the name the user just entered

Variable syntax extension

To update the variable

When a variable is reassigned, its original value is overwritten, and the value of the variable is the last value assigned

var age = 18; age = 81; // The final result is 81, because 18 is covered

Declare multiple variables at the same time

To declare multiple variables at the same time, write only one var and separate the variable names with commas (,)

var age = 10, name = ‘xx’, sex = 1;

Declare variable special case

Example: Swap the values of two variables

The data type of a variable

JavaScript is a weakly typed or dynamic language, which means that the type of a variable is not declared in advance, but is determined automatically as the program runs

var age = 10; Var areYouOk = ‘yes ‘; // This is a string

When the code runs, the data type of the variable is determined by the JS engine according to the data type of the value of the variable on the right of =. After running, the data type of the variable is determined.

JavaScript has dynamic typing, which also means that the same variable can be used for different types:

var x = 6; Var x = ‘Bill’; //x is a string

Simple data types (basic data types)

Digital type Number

Numeric base system: common: binary, octal, decimal, hexadecimal

7 var num1 = 07; Var num2 = 019; Var num3 = 08; Hexadecimal number sequence range: 0, 9 and A~F var num = 0xA;

Remember to prefix octal with 0 and hexadecimal with 0x in JS

Numerical range

Maximum and minimum values for numeric values in JavaScript

alert(Number.MAX_VALUE); / / 1.7976931348623157 e+308 alert (Number. MIN_VALUE); //5e-324

Three special values

alert(Infinity); //Infinity, Infinity, greater than any value alert(-infinity); // -infinity, representing infinitesimal, less than any numeric value alert(NaN); //NaN, which represents a non-numeric value

isNaN()

Used to determine whether a variable is of a non-numeric type and returns true or false

var usrAge = 21; var isOk = isNaN(usrAge); console.log(isNum); Var userName = ‘userName ‘; console.log(isNaN(userName)); //true,’ Po ‘is a non-number

String

A string can be any text within quotation marks. The syntax is double quotation marks or single quotation marks

Var strMsg = “I love Beijing tiananmen ~”; Var strMsg2 = ‘WDNMD’; Var strMsg3 = hahaha; // Error without quotation marks is considered js code, but JS does not have this syntax

Because attributes in HTML tags use double quotation marks, we prefer to use single quotation marks

String escape character

A web warning box is displayed

< !DOCTYPE html>

< HTML > < head> < meta charset=” UTF-8 “> < title> < script type=”text/javascript”> alert I look around, here, is my stage, I am the king of heaven and earth. At this moment, I am heroic, and finally shouted out: “rubbish ~”); < /script> < /head> < body> < /body> < /html>

String length

The length property of the string is used to obtain the length of the entire string

Var strMsg = ‘I am Po! ‘; alert(strMsg.length); / / show 5

String splicing

//1.1 string “add” alert(‘hello’ + ‘ ‘+ ‘world’); / / hello world / / 1.2 numerical string “addition” alert (‘ 100 ‘+’ 100 ‘); //100100 //1.3 Value string + value alert(’11’ + 12); / / 1112

+ sign summary formula: add values, join characters

String concatenation enhancement

Console. log(‘ Po ‘+ 18); Var age = 18; //console.log(‘ age is old ‘); Console. log(‘ apo ‘+ age); // console. Log (‘ console ‘+ age +’ age ‘); // Po is 18 years old

The Boolean

Boolean types have two values: true and false, where true means true (true) and false means false (false)

When Boolean and numerals are added, true has the value 1 and false has the value 0

console.log(true + 1); //2 console.log(false + 1); / / 1

Undefined and Null

A declared variable that has not been assigned a value will have a default value of undefined

var variable; console.log(variable); //undefined console.log(‘ hello ‘+ variable); // undefined console.log(11 + variable); //NaN console.log(true + variable); //NaN

A declaration variable is given to a null value, in which the value is null

var vari = null; Console. log(‘ hello ‘+ vari); // hello null console.log(11 + vari); //11 console.log(true + vari); / / 1

Gets the data type Typeof the test variable

Data type conversion

In plain English, a variable of one data type is converted to another data type

There are three conversion modes:

  1. To a string type
  2. Convert to an alphanumeric
  3. Convert to Boolean

Convert to string

Conversion to Alphanumeric (emphasis)

Calculating age cases

Simple adder case

Convert to Boolean

Values representing null and negative are converted to false, such as “, 0, NaN, null, undefined

All other values are converted to true

console.log(Boolean(”)); //false console.log(Boolean(0)); //false console.log(Boolean(NaN)); //false console.log(Boolean(null)); //false console.log(Boolean(undefined)); //false console.log(Boolean(‘ small white ‘)); //true console.log(Boolean(12)); //true

Well, this is the end of today’s article, I hope to help you confused in front of the screen