---
tags: Javascript
---
Je sui le chef de cette.
# Undefined in Javascript
## Fairly comprehensive answer
https://stackoverflow.com/questions/22844840/why-does-javascript-variable-declaration-at-console-results-in-undefined-being
## Completion type and control flow
The Completion type is a Record used to explain the runtime propagation of values and control flow such as the behaviour of statements (break, continue, return and throw) that perform nonlocal transfers of control.
https://262.ecma-international.org/6.0/#sec-completion-record-specification-type
## Behaviour of eval statement and examples
Let result be the result of evaluating the program prog.
If result.type is normal and its completion value is a value V, then return the value V.
If result.type is normal and its completion value is empty, then return the value undefined.
https://262.ecma-international.org/5.1/#sec-15.1.2.1##
## Variable statement and Expression statement
See https://interglacial.com/javascript_spec/a-12.html
Statement and Expression: https://medium.com/launch-school/javascript-expressions-and-statements-4d32ac9c0e74
## Examples
eval("function f(){}"); // Return (normal, empty, empty)
eval(";"); // Return (normal, empty, empty)
eval("(function f(){})"); // (normal, GetValue(exprRef), empty), PrimaryExpression < ExpresionStatement
function foo() {return 5;}
foo(); // (return, 4, empty)
eval("function foo() {return 5;}"); // Return (normal, empty, empty)
eval("foo();") //(return, 4, empty)
let x = 4; if (x>3) {console.log(x)}
console.log(6)
eval("let x = 4; if (x>3) {console.log(x)}")
let y = 5; do {console.log(3); y++;} while (y<8)
do {console.log(3);} while (y<8)