search
HomeWeb Front-endJS TutorialLecture 1 of 'Advanced Programming with JavaScript' -- Basic Concepts

I have read the book "JavaScript Advanced Programming" several times before, but I have never read it completely. From now on, I will read it completely and record notes and my own thoughts on each chapter. Come on!

Since the content of the first three chapters is relatively simple, I will put them into one chapter to record the learning process.

1. Basic concepts

1. The relationship between JavaScript and ECMAScript

It can be understood that in addition to ECMAScript, JavaScript contains Also includes DOM (Document Object Model), BOM (Browser Object Model)

2, <script> tag</script>

  • Attributes: async defer charset type src

The difference between defer and async: (only applicable to external script files)

Without async or defer, the <script> tags are parsed in sequence. The browser will load and execute the specified script immediately. "Immediately" refers to before rendering the document element under the <code>script tag. That is to say, it does not wait for subsequent loading of document elements. Load and execute. </script>

With async, the process of loading and rendering subsequent document elements will be carried out in parallel with the loading and execution of js (asynchronously);

With defer, the process of loading subsequent document elements will be parallel with the loading of js Proceed in parallel (asynchronous), but the execution of js must be completed after all elements are parsed and before the DOMContentLoaded event is triggered

The blue line represents network reading, and the red line represents Execution time, both are for scripts; the green line represents HTML parsing.

Click for detailed analysis

  • ## Tag position: can be placed behind the content in the or element

  • Document mode: (can be divided into mixed mode and standard mode)

The difference between browser mode and document mode in IE:

Browser mode: It affects the browser version and IE’s conditional comments.

Document mode: It affects IE’s layout engine and DOM rendering.

Click for detailed analysis

3. Data type

5 simple data types: String, Number, Boolean, Null, Undefined 1 complex data type: Object

The typeof operator detects the variable Data type, return string

Note: typeof null returns 'object', null is considered an empty object reference

When the variable is not initialized or declared, typeof All return undefined

 ----- Boolean type

#Data typeConvert to true value Value converted to falseBooleantruefalseStringNon-empty stringEmpty stringNumberAny non-zero numeric value (including infinity)0 and NaNObjectAny objectnullUndefinedNot applicable undefined

 -----Number type

 The calculation of floating point numbers in js is not accurate, use it with caution~

 isFinite() Determines whether a number is within the minimum sum The largest number between ​

 NaN Non-numeric value, not equal to anything, including itself ​ ​ ​ isNaN() ​

  Non-numeric value converted to numeric value: Number() Number('') 0 Number( null) 0

     parseInt() parseFloat() If the first character is not a numeric character or a negative sign, then NaN is returned parseInt('') NaN parseInt(null) NaN

--- -- String type

Method to convert string: toString() Except for null and undefined, this method is available. String() can convert any type of value into a string. Plus operator +''

  ----- Object type

Each instance of Object has the following properties and methods

Constructor: Saves the function used to create the current object

hasOwnProperty(propertyName): Whether the property exists in the current object instance

isPrototypeOf(object): Whether the incoming object is the prototype of another object

PropertyIsEnumerable(propertyName): Whether the property can be used for-in statement to enumerate

  toLocaleString()

  toString(): Returns the string representation of the object

  valueOf(): Returns the string, numeric or value of the object Boolean value representation

4, operator

 var age = 10; var newAge = ++age; console.log(age); //11 console.log(newAge) ; //11 ++age is added first and then assigned, that is, first age+1, and then assign the value to newAge

var age = 10; var newAge = age++; console.log( age); //11 console.log(newAge); //10 ++age is assigned first and then added, that is, assign the value to newAge first, then age+1

 ----- Bitwise operator

Bitwise not (~) means the negative value of the operand is reduced by 1

Bitwise AND (&) returns 1 only when the corresponding bits of both values ​​are 1, any one If the bit is 0, the result is 0

Bitwise OR (|) returns 1 if one bit is 1

Bitwise XOR (^) The corresponding bits of the two values ​​only have Returns 1 only when there is a 1

Left shift (

Signed right shift (>>) fills the empty bits with the value of the sign bit

Unsigned right shift (>>>) fills the empty bits with 0

 ----- Boolean operator

Logical NOT (!)

Logical AND (&&) short-circuit operator, that is, if the first operand evaluates to false, then The second operand will not be evaluated eg:console.log(1 && 2 && 3); //3

Logical OR (||) short-circuit operator, that is, the If the evaluation result of one operand is true, the second operand will not be evaluated eg:console.log(1 || 2 || 3); //1

 ----- Equality operator

 null >= 0 //true null == 0 //false Reason: The relational operator will be converted into a numerical value when compared, but the equality operator will not Will

 

null == undefined //true null == 0 //false undefined == 0 //false

 = =Only compare values ​​===Compare both values ​​and types

A question asked in the previous interview: var a = 1, b = 1; var c = {a: 1}, d = {a:1}; console.log(a == b); console.log(a === b); console.log(c == d); console.log(c === d); //true true false false

When the comma expression is used for assignment, it will always return the last item in the expression eg:var num=(1,2,3 ); console.log(num); //3

5. Statement

do{} while () statement while() {} statement switch statement

For-in statement: can be used to enumerate the properties of an object. The order of returning properties may vary depending on the browser

break statement: exit the loop and execute the statement after the loop continue: jump out of this loop, Execute the next loop

6, function

The arguments object can access the array of parameters. The value of the parameters can be obtained through arguments[0]..., and has the length attribute

Functions that do not specify a return value return an undefined value. This is why sometimes entering some commands in the chrome console will return undefined~

 

 

The above is the detailed content of Lecture 1 of 'Advanced Programming with JavaScript' -- Basic Concepts. For more information, please follow other related articles on the PHP Chinese website!

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
js字符串转数组js字符串转数组Aug 03, 2023 pm 01:34 PM

js字符串转数组的方法:1、使用“split()”方法,可以根据指定的分隔符将字符串分割成数组元素;2、使用“Array.from()”方法,可以将可迭代对象或类数组对象转换成真正的数组;3、使用for循环遍历,将每个字符依次添加到数组中;4、使用“Array.split()”方法,通过调用“Array.prototype.forEach()”将一个字符串拆分成数组的快捷方式。

js中new操作符做了哪些事情js中new操作符做了哪些事情Nov 13, 2023 pm 04:05 PM

js中new操作符做了:1、创建一个空对象,这个新对象将成为函数的实例;2、将新对象的原型链接到构造函数的原型对象,这样新对象就可以访问构造函数原型对象中定义的属性和方法;3、将构造函数的作用域赋给新对象,这样新对象就可以通过this关键字来引用构造函数中的属性和方法;4、执行构造函数中的代码,构造函数中的代码将用于初始化新对象的属性和方法;5、如果构造函数中没有返回等等。

入门Java爬虫:认识其基本概念和应用方法入门Java爬虫:认识其基本概念和应用方法Jan 10, 2024 pm 07:42 PM

Java爬虫初探:了解它的基本概念与用途,需要具体代码示例随着互联网的快速发展,获取并处理大量的数据成为企业和个人不可或缺的一项任务。而爬虫(WebScraping)作为一种自动化的数据获取方法,不仅能够快速地收集互联网上的数据,还能够对大量的数据进行分析和处理。在许多数据挖掘和信息检索项目中,爬虫已经成为一种非常重要的工具。本文将介绍Java爬虫的基本概

用JavaScript模拟实现打字小游戏!用JavaScript模拟实现打字小游戏!Aug 07, 2022 am 10:34 AM

这篇文章主要为大家详细介绍了js实现打字小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

php可以读js内部的数组吗php可以读js内部的数组吗Jul 12, 2023 pm 03:41 PM

php在特定情况下可以读js内部的数组。其方法是:1、在JavaScript中,创建一个包含需要传递给PHP的数组的变量;2、使用Ajax技术将该数组发送给PHP脚本。可以使用原生的JavaScript代码或者使用基于Ajax的JavaScript库如jQuery等;3、在PHP脚本中,接收传递过来的数组数据,并进行相应的处理即可。

js是什么编程语言?js是什么编程语言?May 05, 2019 am 10:22 AM

js全称JavaScript,是一种具有函数优先的轻量级,直译式、解释型或即时编译型的高级编程语言,是一种属于网络的高级脚本语言;JavaScript基于原型编程、多范式的动态脚本语言,并且支持面向对象、命令式和声明式,如函数式编程。

js原生选择器有哪些js原生选择器有哪些Oct 16, 2023 pm 03:42 PM

js原生选择器有getElementById()、getElementsByClassName()、getElementsByTagName()、querySelector()和querySelectorAll()等。详细介绍:1、getElementById()通过元素的唯一标识符来选择元素,它返回具有指定ID的元素作为结果等等。

学会使用5个常用的Java工作流框架的基本概念和用法:从入门到精通学会使用5个常用的Java工作流框架的基本概念和用法:从入门到精通Dec 27, 2023 pm 12:26 PM

从零开始:掌握5个Java工作流框架的基本概念与用法引言在软件开发领域,工作流是一种重要的概念,用于描述和管理复杂的业务流程。Java作为一种广泛应用的编程语言,也有许多优秀的工作流框架供开发者选择。本文将介绍5个Java工作流框架的基本概念与用法,帮助读者快速上手。一、ActivitiActiviti是一个开源的BPM(BusinessProcessM

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment