Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this JS snippet do? `"development" !== 'production'`

It's all over this react.js file:

if ("development" !== 'production') {
  var typeofSpec = typeof spec;
  var isMixinValid = typeofSpec === 'object' && spec !== null;

  "development" !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
}

When would it ever be false? In what way is it useful? Was it autogenerated?

like image 787
DiegoSalazar Avatar asked Nov 05 '16 22:11

DiegoSalazar


People also ask

How does the this keyword work?

“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object.

Does JavaScript run Top to bottom?

In interpreted languages, the code is run from top to bottom and the result of running the code is immediately returned. You don't have to transform the code into a different form before the browser runs it.


1 Answers

The purpose of "development" !== 'production' is to enable development mode. The reason it is done this way is so that the block is removed from the production build during minification.

When building for production, "production" !== "production" can never be true, so the block is removed by the minifier.

like image 120
Clint Avatar answered Oct 04 '22 03:10

Clint