Proper use of const for defining functions

There’s no problem with what you’ve done, but you must remember the difference between function declarations and function expressions. A function declaration, that is: function doSomething () {} Is hoisted entirely to the top of the scope (and like let and const they are block scoped as well). This means that the following will work: … Read more

Are variables declared with let or const hoisted?

@thefourtheye is correct in saying that these variables cannot be accessed before they are declared. However, it’s a bit more complicated than that. Are variables declared with let or const not hoisted? What is really going on here? All declarations (var, let, const, function, function*, class) are “hoisted” in JavaScript. This means that if a … Read more

Is it possible to import modules from all files in a directory, using a wildcard?

I don’t think this is possible, but afaik the resolution of module names is up to module loaders so there might a loader implementation that does support this. Until then, you could use an intermediate “module file” at lib/things/index.js that just contains export * from ‘ThingA’; export * from ‘ThingB’; export * from ‘ThingC’; and … Read more

Can I use ES6’s arrow function syntax with generators? (arrow notation)

Can I use ES6’s arrow function syntax with generators? You can’t. Sorry. According to MDN The function* statement (function keyword followed by an asterisk) defines a generator function. From a spec document (my emphasis): The function syntax is extended to add an optional * token: FunctionDeclaration: “function” “*”? Identifier “(” FormalParameterList? “)” “{” FunctionBody “}”

where is create-react-app webpack config and files?

If you want to find webpack files and configurations go to your package.json file and look for scripts You will find that scripts object is using a library react-scripts Now go to node_modules and look for react-scripts folder react-script-in-node-modules This react-scripts/scripts and react-scripts/config folder contains all the webpack configurations.

When to use ES6 class based React components vs. functional ES6 React components?

New Answer: Much of the below was true, until the introduction of React Hooks. componentDidUpdate can be replicated with useEffect(fn), where fn is the function to run upon rerendering. componentDidMount methods can be replicated with useEffect(fn, []), where fn is the function to run upon rerendering, and [] is an array of objects for which … Read more

Why was the name ‘let’ chosen for block-scoped variable declarations in JavaScript?

Let is a mathematical statement that was adopted by early programming languages like Scheme and Basic. Variables are considered low level entities not suitable for higher levels of abstraction, thus the desire of many language designers to introduce similar but more powerful concepts like in Clojure, F#, Scala, where let might mean a value, or … Read more