I didn't know what to answer to my students
javascript
Solution
Unlike some other languages, JavaScript allows expressions as statements, see §12.4 ("Expression Statement") of the specification. So that code is valid, it just doesn't have any enduring effect.
It's the same reason that this works:
foo && foo();
That's a freestanding expression just like your `1+3;`. In this case, of course, it calls `foo` only if `foo` is not falsey.
Philipp points out in the comments that ECMAScript5's `"use strict";` is another example of this. Technically in ECMAscript5 it's a directive, but it works with pre-ECMAScript5 engines because to them it looks like an expression statement.
And what could I say when you enter some assignation in the command line, like `var i=5;` the return result is undefined?
Because statements don't have a result, only expressions. `var` is a statement. If you did them separately, you'd get this:
> var i;
undefined
> i=5;
5
...because the result of an assignment expression is the value being assigned.
Problem
My students are very beginners. When I taught them JavaScript, I showed them this function declaration: ``` function test() { /* code */ } ``` Then I showed them that you could do some input directly into the console of the Webbrowser. I then show them arithmetic operations: `1+2`, `6*3` and so on. One of my students asked me to try this and I was pretty sure it would not work but it did: ``` function test() { 1+3; } ``` What could I say to explain this? And what could I say when you enter some assignation in the command line, like `var i=5;` the return result is `undefined`?