Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6543989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:24:44+00:00 2026-05-25T11:24:44+00:00

The following code passes JSLint: var sGreeting = ‘hello world’; switch (sGreeting) { case

  • 0

The following code passes JSLint:

var sGreeting = 'hello world';

switch (sGreeting)
{
case 'Hello world!':
    var a = 'some a value';
    break;
case 'Kamusta mundo!':
    var b = 'some b value';
    break;
case 'Salut le Monde!':
    var c = 'some c value';
    break;
default:
    break;
}

However, once I put that code in a function, JSLint complains that I should Combine ... with the previous 'var' statement. If I follow JSLint, I would be defining variables that may never need to be used. How should I deal with this problem? Here’s the code followed by JSLint’s errors:

function foo()
{
    'use strict';
    var sGreeting = 'hello world';

    switch (sGreeting)
    {
    case 'Hello world!':
        var a = 'some a value';
        break;
    case 'Kamusta mundo!':
        var b = 'some b value';
        break;
    case 'Salut le Monde!':
        var c = 'some c value';
        break;
    default:
        break;
    }
}


Error:
Problem at line 9 character 7: Combine this with the previous 'var' statement.
var a = 'some a value';

Problem at line 12 character 7: Combine this with the previous 'var' statement.
var b = 'some b value';

Problem at line 15 character 7: Combine this with the previous 'var' statement.
var c = 'some c value';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:24:45+00:00Added an answer on May 25, 2026 at 11:24 am

    The only scope in javascript is functional scope (braces do not provide scope), so those vars in the switch statement are being hoisted to the top of the function.

    What jslint is suggesting is this:

    function foo() {
        'use strict';
        var a, b, c, sGreeting;
    
        sGreeting = 'hello world';
    
        switch (sGreeting) {
        case 'Hello world!':
            a = 'some a value';
            break;
        case 'Kamusta mundo!':
            b = 'some b value';
            break;
        case 'Salut le Monde!':
            c = 'some c value';
            break;
        default:
            break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code does not produce an exception but instead passes the value 4
Following code iterates through many data-rows, calcs some score per row and then sorts
How would you fix the following bad code that passes too many parameters around?
Given the following code : <body> <img src=source.jpg /> <p> <img src=source.jpg id =hello
The following (simplified version of our) code passes our JUnit tests under Hibernate, but
I have the following code running and as time passes by (an hour or
First, some visualization of the code. I have the following images that are dynamically
I'm trying to break-down the following code in Django to figure out what it's
I'm using the following code to send POST request if validation passes. But it
Ok, so I've got the following code structure: var environment:AvEnvironment = new AvEnvironment(stage.stageWidth, stage.stageHeight);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.