summaryrefslogtreecommitdiff
path: root/doc/api/repl.md
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2016-12-13 01:28:33 +0200
committerAnna Henningsen <anna@addaleax.net>2016-12-25 19:49:05 +0100
commitc919dd778874490ca9e50253d6e3de4d39200d98 (patch)
treeb6a2645bc9ea2abeed505c8e9c2d57f85f209aba /doc/api/repl.md
parent45c9ca7fd430022a9c0567e1b9f535b3e3f956fd (diff)
downloadandroid-node-v8-c919dd778874490ca9e50253d6e3de4d39200d98.tar.gz
android-node-v8-c919dd778874490ca9e50253d6e3de4d39200d98.tar.bz2
android-node-v8-c919dd778874490ca9e50253d6e3de4d39200d98.zip
doc: var => let / const in repl.md
PR-URL: https://github.com/nodejs/node/pull/10244 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/repl.md')
-rw-r--r--doc/api/repl.md22
1 files changed, 11 insertions, 11 deletions
diff --git a/doc/api/repl.md b/doc/api/repl.md
index 9ff416e004..ce8ddacc39 100644
--- a/doc/api/repl.md
+++ b/doc/api/repl.md
@@ -78,15 +78,15 @@ The default evaluator supports direct evaluation of JavaScript expressions:
```js
> 1 + 1
2
-> var m = 2
+> const m = 2
undefined
> m + 1
3
```
-Unless otherwise scoped within blocks (e.g. `{ ... }`) or functions, variables
-declared either implicitly or using the `var` keyword are declared at the
-`global` scope.
+Unless otherwise scoped within blocks or functions, variables declared
+either implicitly, or using the `const`, `let`, or `var` keywords
+are declared at the global scope.
#### Global and Local Scope
@@ -96,7 +96,7 @@ it to the `context` object associated with each `REPLServer`. For example:
```js
const repl = require('repl');
-var msg = 'message';
+const msg = 'message';
repl.start('> ').context.m = msg;
```
@@ -115,7 +115,7 @@ To specify read-only globals, context properties must be defined using
```js
const repl = require('repl');
-var msg = 'message';
+const msg = 'message';
const r = repl.start('> ');
Object.defineProperty(r.context, 'm', {
@@ -183,7 +183,7 @@ to the provided callback function:
```js
function eval(cmd, context, filename, callback) {
- var result;
+ let result;
try {
result = vm.runInThisContext(cmd);
} catch (e) {
@@ -275,7 +275,7 @@ function initializeContext(context) {
context.m = 'test';
}
-var r = repl.start({prompt: '>'});
+const r = repl.start({prompt: '>'});
initializeContext(r.context);
r.on('reset', initializeContext);
@@ -321,7 +321,7 @@ The following example shows two new commands added to the REPL instance:
```js
const repl = require('repl');
-var replServer = repl.start({prompt: '> '});
+const replServer = repl.start({prompt: '> '});
replServer.defineCommand('sayhello', {
help: 'Say hello',
action: function(name) {
@@ -430,7 +430,7 @@ without passing any arguments (or by passing the `-i` argument):
```js
$ node
-> a = [1, 2, 3];
+> const a = [1, 2, 3];
[ 1, 2, 3 ]
> a.forEach((v) => {
... console.log(v);
@@ -502,7 +502,7 @@ socket, and a TCP socket:
```js
const net = require('net');
const repl = require('repl');
-var connections = 0;
+let connections = 0;
repl.start({
prompt: 'Node.js via stdin> ',