Skip to content

Commit 37cb971

Browse files
vsemozhetbytevanlucas
authored andcommitted
doc: var => let / const in repl.md
PR-URL: #10244 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6f8c613 commit 37cb971

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

doc/api/repl.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ The default evaluator supports direct evaluation of JavaScript expressions:
7878
```js
7979
> 1 + 1
8080
2
81-
> var m = 2
81+
> const m = 2
8282
undefined
8383
> m + 1
8484
3
8585
```
8686

87-
Unless otherwise scoped within blocks (e.g. `{ ... }`) or functions, variables
88-
declared either implicitly or using the `var` keyword are declared at the
89-
`global` scope.
87+
Unless otherwise scoped within blocks or functions, variables declared
88+
either implicitly, or using the `const`, `let`, or `var` keywords
89+
are declared at the global scope.
9090

9191
#### Global and Local Scope
9292

@@ -96,7 +96,7 @@ it to the `context` object associated with each `REPLServer`. For example:
9696

9797
```js
9898
const repl = require('repl');
99-
var msg = 'message';
99+
const msg = 'message';
100100

101101
repl.start('> ').context.m = msg;
102102
```
@@ -115,7 +115,7 @@ To specify read-only globals, context properties must be defined using
115115

116116
```js
117117
const repl = require('repl');
118-
var msg = 'message';
118+
const msg = 'message';
119119

120120
const r = repl.start('> ');
121121
Object.defineProperty(r.context, 'm', {
@@ -183,7 +183,7 @@ to the provided callback function:
183183

184184
```js
185185
function eval(cmd, context, filename, callback) {
186-
var result;
186+
let result;
187187
try {
188188
result = vm.runInThisContext(cmd);
189189
} catch (e) {
@@ -275,7 +275,7 @@ function initializeContext(context) {
275275
context.m = 'test';
276276
}
277277

278-
var r = repl.start({prompt: '>'});
278+
const r = repl.start({prompt: '>'});
279279
initializeContext(r.context);
280280

281281
r.on('reset', initializeContext);
@@ -321,7 +321,7 @@ The following example shows two new commands added to the REPL instance:
321321
```js
322322
const repl = require('repl');
323323

324-
var replServer = repl.start({prompt: '> '});
324+
const replServer = repl.start({prompt: '> '});
325325
replServer.defineCommand('sayhello', {
326326
help: 'Say hello',
327327
action: function(name) {
@@ -421,7 +421,7 @@ without passing any arguments (or by passing the `-i` argument):
421421

422422
```js
423423
$ node
424-
> a = [1, 2, 3];
424+
> const a = [1, 2, 3];
425425
[ 1, 2, 3 ]
426426
> a.forEach((v) => {
427427
... console.log(v);
@@ -493,7 +493,7 @@ socket, and a TCP socket:
493493
```js
494494
const net = require('net');
495495
const repl = require('repl');
496-
var connections = 0;
496+
let connections = 0;
497497

498498
repl.start({
499499
prompt: 'Node.js via stdin> ',

0 commit comments

Comments
 (0)