I'm totally cool with this JSLint error. How can I tolerate it? Is there a flag or checkbox for it?
You get it when you do stuff like:
v && arr.push(v);
as opposed to:
if (v) { arr.push(v); }
Both do the same exact thing. If you put:
window.test = function(v) { 'use strict'; var arr = []; if (v) { arr.push(v); } return arr; };
into the minifier it minifies down to this anyway:
window.test=function(a){var b=[];a&&b.push(a);return b};
js error "Expected an assignment or function call and instead saw an expression" occurs when we forget to return a value from a function. To solve the error, make sure to explicitly use a return statement or implicitly return using an arrow function.
In React, the onClick handler allows you to call a function and perform an action when an element is clicked. onClick is the cornerstone of any React app. Click on any of the examples below to see code snippets and common uses: Call a Function After Clicking a Button.
I don't think JSLint has an option to turn that off.
JSHint (a fork with more options) has an option for it, though: The expr
option, documented as "if ExpressionStatement should be allowed as Programs".
You can add the following line to ignore that warning:
/*jshint -W030 */
You can read more about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With