If you are not sure if the website you would like to visit is secure, you can verify it here. Enter the website address of the page and see parts of its content and the thumbnail images on this site. None (if any) dangerous scripts on the referenced page will be executed. Additionally, if the selected site contains subpages, you can verify it (review) in batches containing 5 pages.
favicon.ico: javascript-tutorial.com/control-structures/the-switch-statement - The switch statement - The com.

site address: javascript-tutorial.com/control-structures/the-switch-statement redirected to: javascript-tutorial.com/control-structures/the-switch-statement

site title: The switch statement - The complete JavaScript Tutorial

Our opinion (on Thursday 19 November 2026 7:10:35 UTC):

GREEN status (no comments) - no comments
After content analysis of this website we propose the following hashtags:



Meta tags:

Headings (most frequently used words):

the, javascript, for, web, objects, keyword, case, switch, statement, summary, chapter, article, toc, about, getting, started, basics, control, structures, data, types, built, in, operators, functions, classes, error, handling, regular, expressions, general, bom, dom, break, groups, default, comparison,

Text of the page (most frequently used words):
the (77), case (29), break (23), for (22), #switch (20), you (18), answer (18), alert (18), javascript (17), #statement (17), this (15), that (14), keyword (11), and (10), example (10), yes (10), introduction (10), with (8), prompt (8), default (8), like (7), let (7), all (7), can (6), action (6), but (6), comparison (6), number (6), will (6), function (6), using (6), operator (6), each (6), operators (6), not (5), loops (5), string (5), need (5), maybe (5), into (4), value (4), great (4), above (4), have (4), ask (4), again (4), cases (4), same (4), methods (4), functions (4), tutorial (3), article (3), your (3), here (3), while (3), compare (3), multiple (3), statements (3), really (3), because (3), result (3), user (3), handle (3), instance (3), checking (3), strings (3), first (3), use (3), another (3), are (3), always (3), match (3), sorry (3), hear (3), later (3), options (3), different (3), groups (3), variable (3), values (3), web (3), object (3), regular (3), expressions (3), catching (3), has (2), languages (2), language (2), list (2), expression (2), perform (2), series (2), strict (2), equality (2), summary (2), course (2), unknown (2), even (2), numbers (2), before (2), instead (2), line (2), allow (2), thing (2), consider (2), fact (2), would (2), used (2), world (2), compared (2), condition (2), check (2), our (2), fallback (2), from (2), enter (2), one (2), other (2), just (2), many (2), omit (2), what (2), exit (2), return (2), possible (2), control (2), structures (2), asp (2), net (2), dom (2), window (2), bom (2), search (2), error (2), types (2), conditional (2), errors (2), try (2), catch (2), fields (2), inheritance (2), getters (2), setters (2), prototypes (2), objects (2), parameters (2), array (2), basics (2), toc (2), localization, suggest, correction, contact, com, 2007, 2026, been, fully, translated, following, preferred, help, translate, click, italian, czech, next, previous, choices, based, kind, else, more, readable, format, remember, uses, why, text, enters, numerical, turning, comparing, change, turn, work, expected, illustrate, means, only, know, done, tolowercase, was, real, scenario, how, sensitive, wrote, converting, lowercase, place, situations, please, pretty, obvious, flaw, doesn, exact, nothing, happen, situation, nice, something, executed, none, relevant, fortunately, allows, modified, version, where, add, see, now, whole, part, variations, negative, response, resulting, message, nope, nay, nix, sometimes, want, several, problem, simply, stack, top, them, code, may, last, since, ends, there, matter, true, programming, consistency, programmers, tend, include, notice, end, requires, properly, either, within, completely, execution, fall, through, below, matching, test, easily, removing, keywords, running, question, then, inside, define, against, might, sound, complicated, look, simple, wpf, php5, jquery, html5, css3, webforms, mvc, location, history, script, tag, general, replace, capturing, regex, flags, throwing, finally, handling, static, classes, extension, property, accessors, properties, recursive, callback, anonymous, optional, chaining, nullish, coalescing, ternary, remainder, logical, modify, assign, increment, decrement, arithmetic, assignment, json, math, date, built, type, conversion, null, undefined, booleans, data, truthy, falsy, variables, basic, syntax, hello, tools, getting, started, libraries, webbrowser, about, chapter, table, contents, complete,


Text of the page (random words):
the switch statement the complete javascript tutorial javascript tutorial toc table of contents chapter article toc the if statement the switch statement the break keyword case groups the default keyword case comparison summary loops for and while loops for of and for in about javascript what is javascript javascript and the webbrowser javascript libraries getting started the tools you need hello world the basics basic javascript syntax variables truthy falsy control structures the if statement the switch statement loops for and while loops for of and for in data types introduction booleans numbers strings null undefined type conversion built in objects introduction number string array the basics array methods date math json operators introduction the assignment operator comparison operators arithmetic operators increment decrement operators modify and assign operators logical operators remainder operator conditional ternary operator nullish coalescing operator optional chaining operator functions introduction function parameters function parameters with default values anonymous functions callback functions recursive functions multiple return values objects introduction properties methods property accessors getters setters prototypes prototypes inheritance extension classes introduction fields methods getters setters inheritance static fields methods error handling introduction catching errors try catch catching throwing errors try catch finally error types conditional catching regular expressions introduction regex flags options search match with regular expressions using capturing groups search replace with regular expressions javascript for web general introduction window dom bom the script tag javascript for web the bom the window object the history object the location object javascript for web the dom introduction javascript asp net mvc asp net webforms c css3 html5 jquery php5 wpf control structures the switch statement the switch statement is like a series of if statements all checking the same variable but with a different action for each possible value it might sound complicated but it s really not just have a look at this simple example let answer prompt do you like javascript switch answer case yes alert that s great break case no alert sorry to hear that break case maybe alert i ll ask again later break in the first line we ask a question then we use the answer variable as the condition for the switch statement inside the switch statement we define multiple possible values to check against the answer variable yes no or maybe using the case keyword each action will result in a different alert the break keyword notice the break keyword used at the end of each case a switch statement requires that you properly exit each case either by using the break keyword or in case you are within a function by using the return keyword to completely exit the function if you omit this execution will fall through to all cases below the one matching the value you can test this easily by removing the break keywords from the example above and running the example again you may omit the last break keyword since the switch statement ends there no matter what but this is not true for all programming languages so for consistency many programmers tend to always include it for all cases case groups sometimes you want several cases to perform the same action no problem because you can simply stack as many case statements on top of each other to allow them to use the same code here s an example let answer prompt do you like javascript switch answer case yes alert that s great break case no case nope case nay case nix alert sorry to hear that break case maybe alert i ll ask again later break as you can see we now have a whole list of options for the no part of the switch statement with different variations of this negative response all resulting in the same message the default keyword the above example has a pretty obvious flaw if the user doesn t enter the exact value to match one of the cases nothing will happen for a situation like this it s nice to have a fallback action something that will be executed if none of the other options are relevant fortunately for us javascript allows us to do just that using the default keyword here s a modified version of the above example where we add this let answer prompt do you like javascript switch answer case yes alert that s great break case no alert sorry to hear that break case maybe alert i ll ask again later break default alert please enter yes no or maybe break with this in place our switch statement can handle all situations because we have a fallback action from the default keyword case comparison another thing we would need to consider if the above example was used in a real world scenario is how each case is compared to the condition for instance we check for yes but strings are always compared case sensitive so if the user wrote yes yes or yes instead our first case would not match we always need to handle this for instance by converting the answer to lowercase before checking it let answer prompt do you like javascript switch answer tolowercase case yes alert that s great break another thing you need to consider is the fact that all comparison is done using the strict equality comparison operator this means that if your expression in the switch statement is a string you can only compare it to another string even if you know that this string is in fact a number allow me to illustrate with an example let answer prompt 41 or 42 switch answer case 41 alert 41 really break case 42 alert 42 of course break default alert unknown answer break this example will not work as expected why because the result of the prompt is a text string even if the user enters a numerical value but we compare it to numbers 41 or 42 you will need to handle this for instance by turning the answer into a number before checking it or by comparing it to strings instead let s change the first line of the example and use the number function to turn the result of the prompt function into a number let answer number prompt 41 or 42 switch answer case 41 alert 41 really break case 42 alert 42 of course break default alert unknown answer break summary with the switch statement you can compare an expression to multiple choices and perform an action based on it kind of like a series of if else if statements but in a more readable format remember that the switch statement uses strict equality comparison the if statement previous loops for and while next this article has been fully translated into the following languages czech italian is your preferred language not on the list click here to help us translate this article into your language javascript tutorial com 2007 2026 contact us suggest correction localization
Thumbnail images (randomly selected): * Images may be subject to copyright.GREEN status (no comments)

    No Images


    Verified site has: 73 subpage(s). Do you want to verify them? Verify pages:

    1-5 6-10 11-15 16-20 21-25 26-30 31-35 36-40 41-45 46-50
    51-55 56-60 61-65 66-70 71-73


    Top 50 hastags from of all verified websites.

    Supplementary Information (add-on for SEO geeks)*- See more on header.verify-www.com

    Header

    HTTP/1.1 302 Redirect
    Content-Type text/html; charset=UTF-8
    Location htt????/javascript-tutorial.com/control-structures/the-switch-statement
    Server Microsoft-IIS/10.0
    X-Powered-By ASP.NET
    Date Thu, 19 Nov 2026 07:10:34 GMT
    Connection close
    Content-Length 194
    HTTP/2 301
    cache-control private
    content-type text/html; charset=utf-8
    location /control-structures/the-switch-statement/
    server Microsoft-IIS/10.0
    set-cookie ASP.NET_SessionId=aqjsqrepyv1ubapdtmlnde0o; path=/; HttpOnly; SameSite=Lax
    x-aspnetmvc-version 5.2
    x-aspnet-version 4.0.30319
    x-powered-by ASP.NET
    date Thu, 19 Nov 2026 07:10:34 GMT
    content-length 158
    HTTP/2 200
    cache-control private
    content-type text/html; charset=utf-8
    server Microsoft-IIS/10.0
    set-cookie ASP.NET_SessionId=hwej10nqpnfnkpesjppkqio4; path=/; HttpOnly; SameSite=Lax
    x-aspnetmvc-version 5.2
    x-aspnet-version 4.0.30319
    x-powered-by ASP.NET
    date Thu, 19 Nov 2026 07:10:34 GMT
    content-length 25279

    Meta Tags

    title="The switch statement - The complete JavaScript Tutorial"
    name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"

    Load Info

    page size25279
    load time (s)0.168623
    redirect count2
    speed download150470
    server IP 142.132.248.53
    * all occurrences of the string "http://" have been changed to "htt???/"