J82
J82

Reputation: 8457

"Expected an assignment or function call and instead saw an expression." - unnecessary console.log?

Using jshint.com, I'm getting the following error: "Expected an assignment or function call and instead saw an expression."

On this line: (headerTop != parseInt($('#content').css('margin-top').slice(0, -2))) ? $('#content').stop().animate({'margin-top': headerTop}, 150) : console.log('');

What can I do to get rid of this error?

Here is that line in context:

function resize() {
    var headerTop = $('#masthead').outerHeight();
    (headerTop != parseInt($('#content').css('margin-top').slice(0, -2))) ? $('#content').stop().animate({'margin-top': headerTop}, 150) : console.log('');
}
resize();
window.onresize = resize;

Upvotes: 1

Views: 1281

Answers (1)

lesssugar
lesssugar

Reputation: 16181

JSLint docs could cast some light on the problem: http://jslinterrors.com/expected-an-assignment-or-function-call

Bascially, what you get is a warning, informing you about the possibiliby of a typo or unnecessary code. This kind of warnings can be supressed via JSHint configuration option - expr. Take a look here: http://jshint.com/docs/options/#expr.

Quick solution is to drop the ternary operator you're using, and simply use an if ... else statement. Between us, what you wrote in the resize() function is reaaaally not readable ;)

Upvotes: 1

Related Questions