@ -78,15 +78,15 @@ The default evaluator supports direct evaluation of JavaScript expressions:
```js
```js
> 1 + 1
> 1 + 1
2
2
> var m = 2
> const m = 2
undefined
undefined
> m + 1
> m + 1
3
3
```
```
Unless otherwise scoped within blocks (e.g. `{ ... }` ) or functions, variables
Unless otherwise scoped within blocks or functions, variables declared
declared either implicitly or using the `var` keyword are declared at the
either implicitly, or using the `const` , `let` , or `var` keywords
`global` scope.
are declared at the global scope.
#### Global and Local Scope
#### Global and Local Scope
@ -96,7 +96,7 @@ it to the `context` object associated with each `REPLServer`. For example:
```js
```js
const repl = require('repl');
const repl = require('repl');
var msg = 'message';
const msg = 'message';
repl.start('> ').context.m = msg;
repl.start('> ').context.m = msg;
```
```
@ -115,7 +115,7 @@ To specify read-only globals, context properties must be defined using
```js
```js
const repl = require('repl');
const repl = require('repl');
var msg = 'message';
const msg = 'message';
const r = repl.start('> ');
const r = repl.start('> ');
Object.defineProperty(r.context, 'm', {
Object.defineProperty(r.context, 'm', {
@ -183,7 +183,7 @@ to the provided callback function:
```js
```js
function eval(cmd, context, filename, callback) {
function eval(cmd, context, filename, callback) {
var result;
let result;
try {
try {
result = vm.runInThisContext(cmd);
result = vm.runInThisContext(cmd);
} catch (e) {
} catch (e) {
@ -275,7 +275,7 @@ function initializeContext(context) {
context.m = 'test';
context.m = 'test';
}
}
var r = repl.start({prompt: '>'});
const r = repl.start({prompt: '>'});
initializeContext(r.context);
initializeContext(r.context);
r.on('reset', initializeContext);
r.on('reset', initializeContext);
@ -321,7 +321,7 @@ The following example shows two new commands added to the REPL instance:
```js
```js
const repl = require('repl');
const repl = require('repl');
var replServer = repl.start({prompt: '> '});
const replServer = repl.start({prompt: '> '});
replServer.defineCommand('sayhello', {
replServer.defineCommand('sayhello', {
help: 'Say hello',
help: 'Say hello',
action: function(name) {
action: function(name) {
@ -421,7 +421,7 @@ without passing any arguments (or by passing the `-i` argument):
```js
```js
$ node
$ node
> a = [1, 2, 3];
> const a = [1, 2, 3];
[ 1, 2, 3 ]
[ 1, 2, 3 ]
> a.forEach((v) => {
> a.forEach((v) => {
... console.log(v);
... console.log(v);
@ -493,7 +493,7 @@ socket, and a TCP socket:
```js
```js
const net = require('net');
const net = require('net');
const repl = require('repl');
const repl = require('repl');
var connections = 0;
let connections = 0;
repl.start({
repl.start({
prompt: 'Node.js via stdin> ',
prompt: 'Node.js via stdin> ',