JavaScript Is the definition of JavaScript closures on MDN wrong? javascript closures definition

I have read another question on stackoverflow, he said:

  • A closure is one way of supporting first-class functions; it is an expression that can reference variables within its scope (when it was first declared), be assigned to a variable, be passed as an argument to a function, or be returned as a function result.
  • Or, a closure is a stack frame which is allocated when a function starts its execution, and not freed after the function returns (as if a 'stack frame' were allocated on the heap rather than the stack!).

But I have also read MDN, it said:

A closure is the combination of a function and the lexical environment within which that function was declared.

I think they are totally different. But if MDN is right,

var a=1;
function printA(){
    console.log(a);
}

this code include a function printA() and its lexical environment(variable a), does it mean this code is closure? Or MDN is wrong?

Answer:1

I use cloud 9 platform. I have php file with several functions call phpFunctions.php: <?php $servername = "127.0.0.1"; $username = "oshrat"; $password = ""; $database = "myDB"; $dbport = 3306;...

I use cloud 9 platform. I have php file with several functions call phpFunctions.php: <?php $servername = "127.0.0.1"; $username = "oshrat"; $password = ""; $database = "myDB"; $dbport = 3306;...

  1. function from script powershell
  2. call function from script matlab
  3. import function from script python
  4. call function from script
  5. call function from script html
  6. call function from script powershell
  7. function from another script unity
  8. call function from script tag
  9. import function from script powershell
  10. call function from script python
  11. run function from script matlab
  12. call function from script bash
  13. run function from script powershell
  14. matlab function from script
  15. bash function from script
  16. powershell function from scriptblock
  17. python function from script
  18. call function from scriptblock powershell
  19. call function from script tag javascript
  20. javascript function from script

For example I have a function Question.prototype.checkAnswer = function(answer1, answer2) { if (answer1.innerHTML == this.correctAnswer) { console.log("correct"); players1.moveCharacter =...

For example I have a function Question.prototype.checkAnswer = function(answer1, answer2) { if (answer1.innerHTML == this.correctAnswer) { console.log("correct"); players1.moveCharacter =...

  1. execute function only once javascript
  2. execute function only once jquery
  3. execute function only once
  4. execute function only once c#
  5. execute function only once python
  6. execute function only once php
  7. js execute function only once
  8. javascript execute function only one time
  9. angular execute function only once
  10. typescript execute function only once
  11. scala execute function only once
  12. jquery execute function only one time

Say I have an express route that takes numbers, adds them all up and returns the total. Normally I would do something like this app.get('/add/:num1/:num2/:num3', (req, res) => { // access and ...

Say I have an express route that takes numbers, adds them all up and returns the total. Normally I would do something like this app.get('/add/:num1/:num2/:num3', (req, res) => { // access and ...

const fs = require('fs'); // const util = require('util'); let text = ``; const files = [`head.txt`,`body.txt`,`leg.txt`,`feet.txt`]; let head,body,leg,feet = ``; //const readFile = util.promisify(...

const fs = require('fs'); // const util = require('util'); let text = ``; const files = [`head.txt`,`body.txt`,`leg.txt`,`feet.txt`]; let head,body,leg,feet = ``; //const readFile = util.promisify(...

  1. async/await function in javascript
  2. async await function
  3. async await function javascript
  4. async await function return value
  5. async await function javascript example
  6. async await function nodejs
  7. async await function js
  8. async await function example
  9. async await function react
  10. async await function typescript
  11. async await function with callback
  12. async await function c#
  13. async await function return promise
  14. async await function return
  15. async await function react native
  16. async await function expression
  17. async await function es6
  18. async await function angular
  19. async await function call
  20. async await function angular 6