A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Filename: core/URI.php
Line Number: 101
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Router::$uri is deprecated
Filename: core/Router.php
Line Number: 127
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$benchmark is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$hooks is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$config is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$log is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$utf8 is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$uri is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$exceptions is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$router is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$output is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$security is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$input is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$lang is deprecated
Filename: core/Controller.php
Line Number: 82
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$db is deprecated
Filename: core/Loader.php
Line Number: 396
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_DB_mysqli_driver::$failover is deprecated
Filename: database/DB_driver.php
Line Number: 371
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Trying to access array offset on true
Filename: libraries/Email.php
Line Number: 978
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$email is deprecated
Filename: core/Loader.php
Line Number: 1283
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 295
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 169
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 238
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 318
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 359
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 289
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Session cannot be started after headers have already been sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$session is deprecated
Filename: core/Loader.php
Line Number: 1283
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Blogs::$user_model is deprecated
Filename: core/Loader.php
Line Number: 358
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/User.php
Line: 7
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 8
Function: __construct
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$load is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$pgmodule is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$benchmark is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$hooks is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$config is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$log is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$utf8 is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$uri is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$exceptions is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$router is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$output is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$security is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$input is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$lang is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$db is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$email is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$session is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$user_model is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home1/biognosy/skmlhometuitions.in/application/controllers/Blogs.php
Line: 234
Function: view
File: /home1/biognosy/skmlhometuitions.in/index.php
Line: 315
Function: require_once
The switch statement in JavaScript | Post Details - SKML Home Tuitions
The switch statement in JavaScript
A switch statement can replace multiple if checks.
It gives a more descriptive way to compare a value with multiple variants.
The syntax
The switch has one or more case blocks and an optional default.
It looks like this:
switch(x) {
case 'value1': // if (x === 'value1')
...
[break]
case 'value2': // if (x === 'value2')
...
[break]
default:
...
[break]
}
The value of x is checked for a strict equality to the value from the first case (that is, value1) then to the second (value2) and so on.
If the equality is found, switch starts to execute the code starting from the corresponding case, until the nearest break (or until the end of switch).
If no case is matched, then the default code is executed (if it exists).
Example
An example of switch (the executed code is highlighted):
let a = 2 + 2;
switch (a) {
case 3:
alert( 'Too small' );
break;
case 4:
alert( 'Exactly!' );
break;
case 5:
alert( 'Too large' );
break;
default:
alert( "I don't know such values" );
}
Here the switch starts to compare a from the first case variant that is 3. The match fails.
Then 4. That’s a match, so the execution starts from case 4 until the nearest break.
If there is no break, then the execution continues with the next case without any checks.
An example without break:
let a = 2 + 2;
switch (a) {
case 3:
alert( 'Too small' );
case 4:
alert( 'Exactly!' );
case 5:
alert( 'Too big' );
default:
alert( "I don't know such values" ); }
In the example above we’ll see sequential execution of three alerts:
alert( 'Exactly!' );
alert( 'Too big' );
alert( "I don't know such values" );
Any expression can be a switch/case argument
Both switch and case allow arbitrary expressions.
For example:
let a = "1";
let b = 0;
switch (+a) {
case b + 1:
alert("this runs, because +a is 1, exactly equals b+1");
break;
default:
alert("this doesn't run");
}
Here +a gives 1, that’s compared with b + 1 in case, and the corresponding code is executed.
Grouping of “case”
Several variants of case which share the same code can be grouped.
For example, if we want the same code to run for case 3 and case 5:
let a = 3;
switch (a) {
case 4:
alert('Right!');
break;
case 3: // (*) grouped two cases
case 5:
alert('Wrong!');
alert("Why don't you take a math class?");
break;
default:
alert('The result is strange. Really.');
}
Now both 3 and 5 show the same message.
The ability to “group” cases is a side-effect of how switch/case works without break. Here the execution of case 3 starts from the line (*) and goes through case 5, because there’s no break.
Type matters
Let’s emphasize that the equality check is always strict. The values must be of the same type to match.
For example, let’s consider the code:
let arg = prompt("Enter a value?");
switch (arg) {
case '0':
case '1':
alert( 'One or zero' );
break;
case '2':
alert( 'Two' );
break;
case 3:
alert( 'Never executes!' );
break;
default:
alert( 'An unknown value' );
}
For 0, 1, the first alert runs.
For 2 the second alert runs.
But for 3, the result of the prompt is a string "3", which is not strictly equal === to the number 3. So, we’ve got a dead code in case 3! The default variant will execute.
Not sure whare to join tuition right for you?
Choose the right one for you.
Get the help of the experts and find a solution that best suits your needs.
Let`s Connect