diff --git a/sections/en-us/common.md b/sections/en-us/common.md index bf57d96..08c5269 100644 --- a/sections/en-us/common.md +++ b/sections/en-us/common.md @@ -1,13 +1,48 @@ # Basic -* `[Common]` Type judgment -* `[Common]` Scope -* `[Common]` Reference +* [`[Common]` Type judgment](/sections/en-us/common.md#Type-judgement) +* [`[Common]` Scope](/sections/en-us/common.md#Scope) +* [`[Common]` Reference](/sections/en-us/common.md#Reference) * `[Common]` Memory release * `[Common]` ES6+ features ## Summary -With diffrence between frontend, there are few chance to work with DOM in backend. So we won't discuss about it. Unlike browser side, backend is directly facing memory, while the work duration is calculated by year, we do more concern about the machine side. +In contrast to frontend, there are few chances to work with DOM in backend, unless we deal with SSR or web crawlers. So we won't discuss about it. Unlike browser side, backend faces memory directly, we concern more about the fundamental knowledge. +## Type judgement +We suffer tortuously from type judgement in JavaScript. Otherwise, TypeScript may not be created. Basically, we recommend to read the source code of [lodash](https://github.com/lodash/lodash). + +Generally, this is a simple opening of an interview. We won't deny a candidate only because of not knowing the value of `undefined == null` is `true`. According to our personal experiences, candidate who cannot answer this question is probably to have a poor foundation. If you have no concept of such kind of question, you may reflect on whether to find a JavaScript book to review for basis. + +Additionally, it is a bonus point if candidate understands TypeScript or flow. + +## Scope + +In an interview, scope is not an easy-to-ask knowledge point but critical in JavaScript. Eleme typically asks questions like `what's the difference between let and var in es6` or asks candidate to interpret a given code example in the beginning, in order to assess how much does a candidate master scope. + +[You Don't Know JS](https://github.com/getify/You-Dont-Know-JS) has a great explanation on scope. Here it is the TOC of the book, we recommend you to do some intensive reading. + +* Chapter 1: What is Scope? +* Chapter 2: Lexical Scope +* Chapter 3: Function vs. Block Scope +* Chapter 4: Hoisting +* Chapter 5: Scope Closures +* ... + +## Reference + +> In JavaScript, which types are pass by reference? And which types are pass by value? How to pass a variable by reference? + +Simply speaking, objects are pass by reference. Basic types are pass by value. We can pass basic types by reference using boxing technique. (More information at note 1) + +Pass by reference and pass by value is a basic question. It is fundamental part to understand how does JavaScript's memory work. It is hardly to have further discussion without understanding reference. + +In coding session, we use questions like `how to write a json object copy function` to assess candidate. + +Sometimes, we ask about the difference between `==` and `===`. And then, `true` or `false` of `[1] == [1]`. Without a good foundation, candidate may make a wrong conclusion because of the wrong understanding of `==` and `===`. + +Note 1: For senior candidates, you are expected to question directly on the question. e.g. There is no pass by reference in JavaScript. There is call by sharing. Read about [Is JavaScript a pass-by-reference or pass-by-value language?](http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language). Though it is advanced, it is common for senior developer with more than 3 years experiences. + +If C++ is mentioned in resume, it is certain to ask `what is the difference between pointer and reference`. diff --git a/sections/zh-cn/io.md b/sections/zh-cn/io.md index 701cacd..2f4ae0a 100644 --- a/sections/zh-cn/io.md +++ b/sections/zh-cn/io.md @@ -65,7 +65,7 @@ const euro = Buffer.from([0xE2, 0x82, 0xAC]); console.log(decoder.write(euro)); // € ``` -当然也可以断断续续的处理. +stringDecoder.write 会确保返回的字符串不包含 Buffer 末尾残缺的多字节字符,残缺的多字节字符会被保存在一个内部的 buffer 中用于下次调用 stringDecoder.write() 或 stringDecoder.end()。 ```javascript const StringDecoder = require('string_decoder').StringDecoder; @@ -199,7 +199,7 @@ pipe 方法最主要的目的就是将数据的流动缓冲到一个可接受的 ## Console -[console.log 正常情况下是异步的, 除非你使用 `new Console(stdout[, stderr])` 指定了一个文件为目的地](https://nodejs.org/dist/latest-v6.x/docs/api/console.html#console_asynchronous_vs_synchronous_consoles). 不过一般情况下的实现都是如下 ([6.x 源代码](https://github.com/nodejs/node/blob/v6.x/lib/console.js#L42)): +[console.log 同步还是异步取决于与谁相连和`os`](https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_a_note_on_process_i_o). 不过一般情况下的实现都是如下 ([6.x 源代码](https://github.com/nodejs/node/blob/v6.x/lib/console.js#L42)),其中`this._stdout`默认是`process.stdout`: ```javascript // As of v8 5.0.71.32, the combination of rest param, template string diff --git a/sections/zh-cn/util.md b/sections/zh-cn/util.md index c49f404..70ef812 100644 --- a/sections/zh-cn/util.md +++ b/sections/zh-cn/util.md @@ -221,10 +221,12 @@ console.log(traversal('.')); ```javascript const glob = require("glob"); -glob("**/*.js", (err, files) { +glob("**/*.js", (err, files) => { if (err) { throw new Error(err); } - console.log('Here you are:', files.map(path.basename)); + files.map((filename) => { + console.log('Here you are:', filename); + }); }); ```