What is JavaScript?
JavaScript
It is a 直译式
scripting language, a 轻量级
's 脚本语言
.
What is a scripting language?
Script language
It refers to the ability it does not have the development of the operating system, but is only used to control the writing of other programs语言
.
JavaScript
It is a kind of 嵌入式(embedded)
language. It provides the core syntax itself is not a lot, need to rely on more features 宿主环境(host)
available. So, the language for embedding in a larger application environments, to call the underlying hosting environment provided API
.
Current common JavaScript
host environment 浏览器
and 服务器环境Node
.
If from 语法
the perspective, JavaScript
it is one 对象模型语言
. A variety of host environments through this model, describing their function and operation of the interface, so that by JavaScript
controlling these functions.
At the same time, JavaScript
also supports 函数式编程
. So in the process of learning, we need to know more about and learn some different methods to solve the problem.
JavaScript
The core section includes a grammar 基本语法构造
and 标准库
, of course, if learning the language also need to learn a different 宿主环境
offer some other API
[This API normally available only in the host environment], in order to facilitate the call when needed.
For example, the environment is often related to the host 浏览器
, it provides an extra API
can be divided into three categories:
- Browser Control class: Operation Browser
- Operation of the various elements of the page: DOM class
- Web class: the Internet to achieve the various functions
And if you 宿主环境
are Node
such 服务器环境
, it will provide a variety of operating systems API
, for example 文件操作API
, 网络通信相关的API
and so on.
JavaScript development
Why studyJavaScript
- Operational capabilities of the browser
- More applications
- More friendly for beginners
- Increasingly powerful performance
The operational capability of the browser:
JavaScript
Birth, as is to 浏览器内置脚本语言
allow developers to operate front-end browser. Although there have been many similar scripting language before, but the current situation, JavaScript
is only a universal browser scripting language, all browsers support.
Developers by JavaScript
allowing web pages to achieve greater display of results, and create a better user experience.
More applications:
With the recent development of
JavaScript
the language from the very beginning it can only be used浏览器
, and gradually spread to服务端
.
1, platform browser
With HTML5
the emergence of the browser function itself is growing, not only can browse the Web, but more and more like a platform, JavaScript
was able to call many system functions, such as local file operations, operating picture, calling camera and microphone and many more. This makes it JavaScript
possible to accomplish many things previously unthinkable.
2、Node
Node
Project makes JavaScript
large-scale projects can be used to develop server-side, with the front and rear ends of the site are JavaScript
developed has become a reality. Some embedded platforms ( Raspberry Pi
) can be installed Node
, so JavaScript
you can develop applications for these platforms.
3, database operations
JavaScript
It can even be used to operate the database. NoSQL
Database concept in itself is JSON(JavaScript Object Notation)
the basis of the birth of the format, most of the NoSQL
database to allow JavaScript
direct manipulation. Based on SQL
the language of open source database PostgreSQL
support JavaScript
as operating language, you can partially replace the SQL
query language.
4, mobile platform development
JavaScript
也正在成为手机应用的开发语言。一般来说,安卓平台使用 Java
语言开发,iOS
平台使用 Objective-C
或 Swift
语言开发。许多人正在努力,让 JavaScript
成为各个平台的通用开发语言。
PhoneGap
项目就是将 JavaScript
和 HTML5
打包在一个容器之中,使得它能同时在 iOS
和安卓上运行。Facebook
公司的 React Native
项目则是将 JavaScript
写的组件,编译成原生组件,从而使它们具备优秀的性能。
Mozilla
基金会的手机操作系统 Firefox OS
,更是直接将 JavaScript
作为操作系统的平台语言,但是很可惜这个项目没有成功。
5、内嵌脚本语言
越来越多的应用程序,将 JavaScript
作为内嵌的脚本语言,比如 Adobe
公司的著名 PDF 阅读器
Acrobat
、Linux 桌面环境 GNOME 3
。
6、跨平台的桌面应用程序
Chromium OS
、Windows 8
等操作系统直接支持 JavaScript
编写应用程序。Mozilla
的 Open Web Apps
项目、Google
的 Chrome App 项目、GitHub
的 Electron 项目、以及 TideSDK 项目,都可以用来编写运行于 Windows
、Mac OS
和 Android
等多个桌面平台的程序,不依赖浏览器。
著名程序员 Jeff Atwood 甚至提出了一条 “Atwood 定律”:
“所有可以用 JavaScript 编写的程序,最终都会出现 JavaScript 的版本。”(Any application that can be written in JavaScript will eventually be written in JavaScript.)
对初学者更加的友好:
1、可以随时随地的使用浏览器进行开发练习。
2、简单化的语法。即使复杂的语法你没有掌握,也可以通过简单的语法实现。
3、与C/C++
、Java
的相似性。如果你学过这两门语言,那么再来学习JavaScript
可以说将会很简单。
日益强大的性能:
1、灵活的语法。
JavaScript
既支持类似C
语言清晰的过程式编程,也支持灵活的函数式编程
,可以用来写并发处理(concurrent)
。这些语法特性已经被证明非常强大,可以用于许多场合,尤其适用异步编程
。
JavaScript
的所有值都是对象,这为程序员提供了灵活性和便利性。因为你可以很方便地、按照需要随时创造数据结构,不用进行麻烦的预定义。
JavaScript
的标准还在快速进化中,并不断合理化,添加更适用的语法特性。
2、支持编译运行
JavaScript
语言本身,虽然是一种解释型语言
,但是在现代浏览器中,JavaScript
都是编译后运行。程序会被高度优化,运行效率接近二进制程序。而且,JavaScript
引擎正在快速发展,性能将越来越好。
此外,还有一种 WebAssembly
格式,它是 JavaScript
引擎的中间码格式,全部都是二进制代码。由于跳过了编译步骤,可以达到接近原生二进制代码的运行速度。各种语言(主要是 C
和 C++
)通过编译成 WebAssembly
,就可以在浏览器里面运行。
3、事件驱动和非阻塞设计
JavaScript
程序可以采用事件驱动(event-driven
)和非阻塞式(non-blocking
)设计,在服务器端适合高并发环境,普通的硬件就可以承受很大的访问量。
JavaScript和H5
JavaScript
这门语言,本身是一门用来在浏览器当中做交互效果的脚本语言
。虽然现在跟当年的环境发生了极大的变化,但是这项功能仍然还保留在JavaScript
的身体里。
而H5
如果从狭义的角度讲,可以解释为html的第五代产品
,html
主要负责页面的结构,而JavaScript
则需要和html
相互配合,负责页面的交互效果。
如果从广义的角度来说,可以解释为新一代的富客户端解决方案
,而对于这种开发需求,JavaScript
更是一个好的伙伴。
同时,如果单纯的从语言本身来看,大家所说的H5
开发,大概可以约等于Html+Css+JavaScript
。
如果从技术层面看,到了H5
的年代,提供给了JavaScript
更多的API
,让开发变得更加灵活。
js(行为):
我们常说,HTML负责页面的结构,CSS则是页面的样式,而js是页面上的行为,负责与用户的交互。
ES:浏览器遵循的标准;
BOM:浏览器对象模型;
DOM:文档对象模型。
在js中,常用的打印语句有:
1、alert();打印到弹出框;
2、document.write();打印到页面;
3、console.log();打印到控制台;
js中的数据类型:
字符型:string(s);
数值型:number(n);
布尔型:Boolean(b);
未赋值:undefined;
对象:object(o);
数组:array(a);
函数:function(fn);
......
数组与函数的本质也是对象。
可以通过typeof判断数据类型,数组与函数的数据类型是object。
变量的命名规则:
1、只能以字母、_、$开头;
2、语义化,以数据类型开头,使用小驼峰命名方式;
3、不用关键字和保留字命名。
小驼峰命名方式:第一个单词小写,后面的单词首字母全部大写。
运算符:
算数运算符:+、-、*、/、%;
关系运算符:>、<、>=、<=、==、===、!=;
逻辑运算符:||、&&、!;
赋值运算符:=、+=、-=、*=、/=、%=;
自增自减运算符:++,--;