5

Why do JSLint complain about & ldquo; Unexpected 'else' after 'return' &...

 2 years ago
source link: https://www.codesd.com/item/why-do-jslint-complain-about-unexpected-else-after-return.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Why do JSLint complain about & ldquo; Unexpected 'else' after 'return' & rdquo;

advertisements

JSLint complains that the following (useless example) code is invalid:

(function (x) {
    "use strict";
    if (x === 1) {
        return 1;
    } else if (x === 2) {
        return -1;
    }
    return 0;
}(1));

Error: Problem at line 4 character 9: Unexpected 'else' after 'return'.

return 1;

Is it seriously suggesting that it's bad to use return statements inside an if/else structure?

It thinks this version is fine:

(function (x) {
    "use strict";
    var returnval = 0;
    if (x === 1) {
        returnval = 1;
    } else if (x === 2) {
        returnval = -1;
    }
    return returnval;
}(1));


It's just telling you that else after return is superfluous. The following is fine:

(function (x) {
    "use strict";
    if (x === 1) {
        return 1;
    }
    if (x === 2) {
        return -1;
    }
    return 0;
}(1));

Related Articles

Why Date :: Calc complaining about & ldquo; not a valid date & rdquo;

Previously, this function worked for me... $this_day = Day_of_Week($lyear, $month, $day); using this lib.. use Date::Calc qw(Add_Delta_Days Day_of_Week Delta_Days); But I need another way to get this same info. the error it returned is Date::Calc::Da

Why do perl complain about & ldquo; Too many arguments for open & rdquo; When I run it in a shell script?

I run my Perl script (gettotal.pl) and it works fine. I managed to get the sum of TOTAL.txt and append the output value to test.txt. But when I run it inside shell script (test.sh) I got this error: Too many arguments for open at /home/daily/scripts/

Why does Perl complain about & ldquo; Could not stat on the file name containing newline & rdquo;?

I am getting an error I do not understand. I am using File:Find to recurse a fylesystem on Windows using Activestate Perl 5.8.8 and trying to stat $File::Find::name; so I am not stat-ing a filename got from a text file scanning requiring chomp-ing or

JSON.parse complains of & ldquo; unexpected end of data & rdquo;

I have the following code: var default_links = '{ "name" : "Google", "url": "https://encrypted.google.com/", "fav_url": "https://encrypted.google.com/favicon.ico" }\n'+ '{ "name" : &quo

Why does the Pycharm inspector complain about & ldquo; d = {} & quot;

When initializing a dictionary with d = {} Pycharm's code inspector generates a warning, saying This dictionary creation could be rewritten as a dictionary literal. If I rewrite it d = dict() the warning goes away. Since {} already is a dictionary li

When I compile my program, why does he complain about the label & ldquo; at the end of the compound statement & rdquo;

When I try to compile my code, I keep getting this error message: badges.c: In function 'badgeAnyColor': badges.c:335: error: label at end of compound statement To help you see where it is complaining about, the complaints are on the last line of the

Why does GHC complain about non-exhaustive models?

When I compile the following code with GHC (using the -Wall flag): module Main where data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) insert :: (Ord a) => a -> Tree a -> Tree a insert x EmptyTree = Node x EmptyTree EmptyTree ins

Why did Emacs complain about the year displayed variable-void in my .emacs file?

I'm trying to implement the solar terms in my .emacs so my "holidays" will display the time when the solar longitude crosses each multiple of 15 degrees. Here is the relevant snipplet. (defun next-solar-term-date (d) (solar-date-next-longitude d

Why does PostgreSQL complain about the '0000-00-00 00:00:00' time stamp?

Per the Postgres manual on date/time, the timestamp type can go from 4713 BC to a bazillion years in the future. So, why does Pg complain that '0000-00-00 00:00:00' is not a valid timestamp?00 is not a valid month number or day number.

Why does the code continue to work even after 'return res.send ();'

I don't understand why code continues to run even after return and res.send() was called. This is a GIST to help to understand. UPDATE: Well, after help of community now discovery and understand that the problem is that return res.send(); occur async

Why do jQuery complain about a "left-handed assignment" & rdquo; ldquo ;?

function auditUpdate(newval) { jQuery("#audit").val() = newval; jQuery("#auditForm").submit(); } Why do I get an error where I try to assign newval to the #audit value?In jQuery you assign a new value with: jQuery("#audit").v

Why do Perl's GD :: Graph complain about & ldquo; Invalid Data Set & rdquo;

I am writing a small program in Perl for my assignment and I am new to Perl. Code that I have written provides me with exactly the same values I need, but I am getting this error while creating bar chart. Invalid data set: 0 at line 67 Line 67 is mar

Why XML :: RSS :: Parser from Perl complain about & ldquo; Discrepancy End Tags'?

I'm a complete noob in all of this, but sometime ago I wrote a little script in Perl to parse an RSS feed. It starts like this: use strict; use XML::RSS::Parser; use Data::Dumper; my $url = "http://www.livenation.co.uk/Venue/159/Southampton-Guildhall

Why this OCaml code receives & ldquo; Unexpectedly token & rdquo;

let rec move_robot (pos: int) (dir: string) (num_moves: int) : int = let new_forward_position = pos + num_moves in if (new_forward_position > 99) then failwith "cannot move beyond 99 steps" else new_forward_position let new_backward_position

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK