Table of Contents
1. Foreword:
2. History of JavaScript
3. ECMAScript
4. JavaScript implementation
Javascript consists of three parts:
(3)位置:关于<script> 在HTML文档中的位置:
六、JavaScript的平稳退化方案
Home Web Front-end JS Tutorial JavaScript learning experience

JavaScript learning experience

Sep 06, 2017 am 10:43 AM
javascript js study

1. Foreword:

I read the Little Red Book (JavaScript Advanced Programming) some time ago, but I didn’t plan to read it, and I didn’t take detailed notes. After reading it, I felt a little empty and felt something was wrong. It’s hard to remember what I learned, and I don’t have a deep impression. I feel frustrated. I can’t even learn how to do front-end using JS. The backend has learned js, you decide whether to die or not.

So I read it, read it again, and decided to blog about it to enhance my impression and make reading notes for future reading and for everyone's reference and discussion.

Warm reminder: Notes and words will be subjective, and knowledge should be recorded with emphasis.

2. History of JavaScript

  • Origin: It is said that in 1995, at the end of the last century, Netscape launched the Navigator browser. The company is pursuing not only static HTML, but also dynamic effects. They also want to be able to handle the verification of the form. Don't always wait until the backend to know whether the form input is legal or not, especially in that era. We waited for minutes at a time, and now we wait for ten seconds without wanting to turn it off, while complaining about some broken website.

  • Get started: Just do it if you have a goal. There are many great people at Netscape. Brendan Eich developed JavaScript in 10 days (it says 10 days online). When it first came out, it was called LiveScript, but in order to capitalize on the popularity of the popular star Java, it was changed to JavaScript, so in fact they have nothing to do with each other.

  • Competition: Seeing that Netscape has js, Microsoft felt that it was not good and my IE was going to be killed. At the same time, it also felt that js had a bright future, so I made a JavaScript implementation called JScript.

  • Standards: The js competition between Netscape and Microsoft has led to version inconsistencies. With industry concerns, the standardization of JavaScript has been put on the agenda. The ECMA organization went to do this, and finally came up with ECMAScript as a standard in 1997. Here ECMAscript and JavaScript can be seen as expressing the same thing

3. ECMAScript

ECMAScript (hereinafter referred to as ES) is formulated by ECMA-262, and ES is mainly about language The basis of grammar is the existence of a standard. If you insist on distinguishing ES and JS, ES is the basic language standard, and JS is the language implemented on the basis of this standard.

About ES versions: ES has gone through many versions since it was formulated in 1997. The previous versions were all minor modifications. Important version:

  • ES3, the third version, is the first real modification to the standard

  • 2009 ES5 is currently supported by all major popular browsers

  • The ES6 published in 2015 has also become popular.

  • Versions will be released every year after 2015, but browsers are not yet able to support it.

4. JavaScript implementation

Javascript consists of three parts:

1.ECMAScript: The core part is the grammatical basis of js. We will continue to write about its syntax later.
2.DOM (Text Object Model): Application programming interface for operating HTML documents. About DOM:

  • The emergence of DOM makes it possible to implement dynamic HTML (DHTML), which can change the appearance and content of web pages without reloading the page.

  • Problems caused by DOM: Mainly in terms of compatibility, Netscape and Microsoft have their own opinions, resulting in browser incompatibility. This problem has not been solved. W3C has started planning DOM

  • ##DOM levels: DOM1, DOM2, DOM3. The levels here are equivalent to the DOM versions, which means that DOM is constantly improving. Now the latest is DOM3

3.BOM (browser model): Use BOM to control parts other than the page displayed by the browser

5. JavaScript usage:

(1) Tag attributes: The key to using js in web pages is to use the

<script> tag, which has 6 attributes:

  1. async: optional , indicating that the script will be downloaded immediately, but will not hinder other operations on the page. That is, asynchronous scripts only apply to external script files.

  2. defer: Optional, indicating that the script can be delayed until the document is completely parsed and displayed. That is, delayed scripts are only suitable for external script files.

  3. src: Optional, indicating an external file containing the code to be executed.

  4. type: Default text/Javascript. js is executed by default and does not need to be specified.

  5. charset: Optional, indicating the character set of the code specified through the src attribute. Most browsers will ignore its value and few people use it.

  6. language: obsolete

    Commonly used are the first 4

(2)Usage: use

<script> : There are two operations:

1. Write the code directly in the tag, that is, embed the code in the html. This method is not recommended. Such as:


<script>
 function helloWorld(){
    alert("hello world!");
 }
 helloWorld();</script>
Copy after login

2. Another way to introduce external files through the src attribute.


<script src="js/hello.js"></script>
Copy after login

Use external reference js files as much as possible, advantages:

  • Maintainability: embedded code in html, maintenance Difficult and poorly readable, it would be much easier to maintain in a separate js file.

  • 可缓存:浏览器可以根据具体的设置缓存链接的所用外部js文件

  • 适应未来:通过外部文件来包含js无须对XHML的特别处理和注释hack。HTML和XHTML的包含文件的语法相同。

特别注意:<script>在使用了src属性后,不要在内嵌代码,此时的内嵌的代码不会被执行。只会执行src对应文件的代码。

(3)位置:关于<script> 在HTML文档中的位置:

在HTML4中规定<script> 标签可以放在 <head><body> 标签内。
由于浏览器解析HTML文档是由上到下,且在遇到<script> 标签后会先解析和执行js代码,并中断HTML的加载,所以放在<head> 标签中是会使得HTML文档可视内容中断加载。
画重点:所以<script> 标签的位置首考虑放在<body> 标签底部。例如:


<html>
    <head>
       <title>hello js</title>
    </head>
    <body>
        <p>hello js!</p>
        <!-- js文件放在body底部 -->
        <script src="example.js"></script>
    </body></html>
Copy after login

六、JavaScript的平稳退化方案

什么是平稳退化:就是有些浏览器不支持js,当然现在几乎没有浏览器这么菜啦,还有就是js功能被禁用。这时就需要没有js的情况下你的网页怎么友好一点交互,不会搞得太难看,太尴尬。
使用<noscript> 标签,应用场景:

  • 浏览器不支持JavaScript

  • 浏览器支持脚本,但脚本被禁止了

例子:当浏览器不支持js或禁用js时就会显示出noscript标签中的内容,若浏览器能执行js则noscript就被隐藏。


<html>
    <head>
        <script src="example.js"></script>
    </head>
    <body>
        <noscript>
         <p>本页面需要浏览器支持JavaScript</p>
        </noscript>
    </body></html>
Copy after login

The above is the detailed content of JavaScript learning experience. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Revealing the appeal of C language: Uncovering the potential of programmers Revealing the appeal of C language: Uncovering the potential of programmers Feb 24, 2024 pm 11:21 PM

The Charm of Learning C Language: Unlocking the Potential of Programmers With the continuous development of technology, computer programming has become a field that has attracted much attention. Among many programming languages, C language has always been loved by programmers. Its simplicity, efficiency and wide application make learning C language the first step for many people to enter the field of programming. This article will discuss the charm of learning C language and how to unlock the potential of programmers by learning C language. First of all, the charm of learning C language lies in its simplicity. Compared with other programming languages, C language

Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Feb 19, 2024 pm 10:10 PM

Learn Pygame from scratch: complete installation and configuration tutorial, specific code examples required Introduction: Pygame is an open source game development library developed using the Python programming language. It provides a wealth of functions and tools, allowing developers to easily create a variety of type of game. This article will help you learn Pygame from scratch, and provide a complete installation and configuration tutorial, as well as specific code examples to get you started quickly. Part One: Installing Python and Pygame First, make sure you have

Let's learn how to input the root number in Word together Let's learn how to input the root number in Word together Mar 19, 2024 pm 08:52 PM

When editing text content in Word, you sometimes need to enter formula symbols. Some guys don’t know how to input the root number in Word, so Xiaomian asked me to share with my friends a tutorial on how to input the root number in Word. Hope it helps my friends. First, open the Word software on your computer, then open the file you want to edit, and move the cursor to the location where you need to insert the root sign, refer to the picture example below. 2. Select [Insert], and then select [Formula] in the symbol. As shown in the red circle in the picture below: 3. Then select [Insert New Formula] below. As shown in the red circle in the picture below: 4. Select [Radical Formula], and then select the appropriate root sign. As shown in the red circle in the picture below:

Learn the main function in Go language from scratch Learn the main function in Go language from scratch Mar 27, 2024 pm 05:03 PM

Title: Learn the main function in Go language from scratch. As a simple and efficient programming language, Go language is favored by developers. In the Go language, the main function is an entry function, and every Go program must contain the main function as the entry point of the program. This article will introduce how to learn the main function in Go language from scratch and provide specific code examples. 1. First, we need to install the Go language development environment. You can go to the official website (https://golang.org

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

Understand these 20 Dune analysis dashboards and quickly capture trends on the chain Understand these 20 Dune analysis dashboards and quickly capture trends on the chain Mar 13, 2024 am 09:19 AM

Original author: Minty, encryption KOL Original compilation: Shenchao TechFlow If you know how to use it, Dune is an all-in-one alpha tool. Take your research to the next level with these 20 Dune dashboards. 1. TopHolder Analysis This simple tool developed by @dcfpascal can analyze tokens based on indicators such as holders’ monthly activity, number of unique holders, and wallet profit and loss ratio. Visit link: https://dune.com/dcfpascal/token-holders2. Token Overview Metrics @andrewhong5297 created this dashboard which provides a way to evaluate tokens by analyzing user actions

The AI ​​era of JS is here! The AI ​​era of JS is here! Apr 08, 2024 am 09:10 AM

Introduction to JS-Torch JS-Torch is a deep learning JavaScript library whose syntax is very similar to PyTorch. It contains a fully functional tensor object (can be used with tracked gradients), deep learning layers and functions, and an automatic differentiation engine. JS-Torch is suitable for deep learning research in JavaScript and provides many convenient tools and functions to accelerate deep learning development. Image PyTorch is an open source deep learning framework developed and maintained by Meta's research team. It provides a rich set of tools and libraries for building and training neural network models. PyTorch is designed to be simple, flexible and easy to use, and its dynamic computation graph features make

See all articles