Comments (13)
Logical operators 逻辑操作符
There are three logical operators in JavaScript: || (OR), && (AND), ! (NOT).
在JavaScript中,有3个逻辑操作符。分别是||(或),&&(且),!(非)。
Although they are called “logical”, they can be applied to values of any type, not only boolean. The result can also be of any type.
虽然叫做逻辑操作符,他们可以用于任意类型(包括布尔类型),返回的结果也一样。
Let’s see the details.
下面我们来看看具体的示例:
I have more than two years javascript development experience , and I a team leader of a small team of FrontEnd Engineers. I have read a lot of books about javascript ,including
- JavaScript: The Good Parts
- JavaScript: The Definitive Guide
- You Don't Know JS seriers
- Professional JavaScript for Web Developers
- ECMA-262-3 in detail (seriers of articals by Dmitry Soshnikov )
from javascript-tutorial.
Error handling, "try..catch"
错误处理 "try..catch"
No matter how great we are at programming, sometimes our scripts have errors. They may occur because of our mistakes, an unexpected user input, an erroneous server response and for a thousand of other reasons.
不管我们在编程方面做的有多好,有时候我们的脚本还是会出现错误。它们可能是因为我们的失误、非预期的用户输入、错误的服务端响应或者其他的上千个原因而发生。
Usually, a script "dies" (immediately stops) in case of an error, printing it to console.
通常情况下,如果发生了错误,脚本会“死掉”(立即停止),并将错误打印到控制台。
But there's a syntax construct try..catch
that allows to "catch" errors and, instead of dying, do something more reasonable.
但是有一个语法结构 —— try..catch
可以允许你来“捕捉”错误,并且做一些更合理的事情,而不是让脚本“死掉”。
[cut]
The "try..catch" syntax
"try..catch" 语法
The try..catch
construct has two main blocks: try
, and then catch
:
try..catch
结构有两个主要的部分:try
, 和 catch
:
try {
// code...
} catch (err) {
// error handling
}
It works like this:
它是这么工作的:
1. First, the code in `try {...}` is executed.
2. If there were no errors, then `catch(err)` is ignored: the execution reaches the end of `try` and then jumps over `catch`.
3. If an error occurs, then `try` execution is stopped, and the control flows to the beginning of `catch(err)`. The `err` variable (can use any name for it) contains an error object with details about what's happened.
- 首先,
try {...}
中的代码会被执行。 - 如果没有错误发生,那么
catch(err)
会被忽略:程序执行完try
,之后跳过catch
。 - 如果有错误发生,
try
中的脚本会被停止执行,并且控制会转移到catch(err)
的开头。err 变量(可以使用任何名称)包含一个错误对象,其中包含了有关发生的情况的详细信息。
from javascript-tutorial.
An introduction to JavaScript
JavaScript的简介
Let's see what's so special about JavaScript, what we can achieve with it and which other technologies play well with it.
让我们看看JavaScript到底有什么特别之处,通过它我们能得到什么,它又能更好地发挥哪些技术。
What is JavaScript?
什么是JavaScript
JavaScript was initially created to "make webpages alive".
JavaScript的最初目的是为了让网页生动起来。
The programs in this language are called scripts. They can be written right in the HTML and execute automatically as the page loads.
这门语言中的程序我们称之为脚本。脚本可以直接写进HTML文档中,然后随着页面加载自动执行。
Scripts are provided and executed as a plain text. They don't need a special preparation or a compilation to run.
脚本可以以纯文本的方式提供并执行,不需要特别的准备或编译就能运行它。
In this aspect, JavaScript is very different from another language called Java.
在这个层面上,JavaScript和另一种编程语言Java就非常不同。
When JavaScript was created, it initially had another name: "LiveScript". But Java language was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help.
But as it evolved, JavaScript became a fully independent language, with its own specification called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), and now it has no relation to Java at all.
在JavaScript被创造的初期,有过另外一个名字:LiveScript。但是当时Java语言非常流行,考虑到对其语言的推广,所以最后决定将它定位于Java的“年轻的小弟”。
但是,随着它的演变,JavaScript编程一个完全独立的语言,有着自己的编程规范,称为“ECMAScript”。可以这么说,现在它和Java一点关系都没有。
At present, JavaScript can execute not only in the browser, but also on the server, or actually on any device where exists a special program called the JavaScript engine.
目前,JavaScript不单单可以在浏览器端执行,还可以在服务器端执行。或者更确切地说,它可以在任何存在JavaScript引擎的设备中执行。
from javascript-tutorial.
I waner join you @sqrthree
from javascript-tutorial.
Translation will be published at cn.javascript.info with credits to translators, sounds good?
from javascript-tutorial.
Great, how shall we start?
from javascript-tutorial.
Are you good at JavaScript?
你可以翻译一点就给我看看?
from javascript-tutorial.
It's nice idea. I am in @sqrthree
from javascript-tutorial.
https://github.com/iliakan/javascript-tutorial-cn is created, with you as collaborators. I'll check the local server, maybe clean it up a little bit and get back to here soon.
from javascript-tutorial.
Okay it's here: https://github.com/iliakan/javascript-tutorial-server -- install it to edit/translate the tutorial locally, the instruction is at https://github.com/iliakan/javascript-tutorial-server/blob/master/INSTALL.md.
Note that it only runs at Unux/MacOS systems, as Windows is not supported by many Node.JS modules. Any of you on Windows? It's possible to make a virtual machine for things to work, had no reason to do it yet.
Also, to translate the illustrations, you need Sketch editor (Mac only). If that's a problem, you can skip them for now and concentrate on the text.
Please synchronize the translation, not to do the same twice.
from javascript-tutorial.
@iliakan Some of our members also want to participate in the translation. Can they join us? BTW, We can maintain the quality of translation by the mutual review.
from javascript-tutorial.
@sqrthree sure, they want commit access, or you will merge their PRs?
from javascript-tutorial.
OK, I can handle their PRs.
from javascript-tutorial.
Related Issues (20)
- Russian used in the EN version of the coding style cheat-sheet HOT 1
- Typo
- Duplicated task name
- Missing comma HOT 2
- Не совсем верно работающий пример #2 HOT 2
- typos HOT 1
- Wrong figure HOT 1
- Search doesn't work properly
- contribution rules HOT 1
- coding styles, automated style linters : duplication HOT 1
- 7 types, 6 of which are "primitive" ? HOT 1
- reference to unresolved property-flags-descriptors HOT 1
- sort() and reverse() on arrays HOT 1
- node seems to handle HOT 2
- Babel HOT 1
- Portuguese (PT-BR) - Translation HOT 1
- Korean Translation HOT 3
- Горизонтальный скролл
- Serbian Translation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript-tutorial.