What causes the different behaviors between “var” and “let” when assign them a returned value of a function which throws an error

Declarations of var variables get hoisted – the variable name initialization gets hoisted to the top of the containing function (or, if no function, to the top of the outer block). So var withVar = (function() {throw ‘error!’})() is parsed by the interpreter as var withVar; withVar = (function() {throw ‘error!’})() The same is not … Read more

What is the difference between “let” and “var”?

Scoping rules The main difference is scoping rules. Variables declared by var keyword are scoped to the immediate function body (hence the function scope) while let variables are scoped to the immediate enclosing block denoted by { } (hence the block scope). function run() { var foo = “Foo”; let bar = “Bar”; console.log(foo, bar); … Read more

When to use a Var instead of a function?

Yes, a Var in Clojure is similar to a C pointer. This is poorly documented. Suppose you create a function fred as follows: (defn fred [x] (+ x 1)) There are actually 3 things here. Firstly, fred is a symbol. There is a difference between a symbol fred (no quotes) and the keyword :fred (marked … Read more

tech