Skip to content

This is a demo show you how you can increase performance of js application.

Notifications You must be signed in to change notification settings

tandonrajiv/js-loop-performace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

js-loop-performace

This is a demo show you how you can increase performance of js application.

Writing short code is very important and well explanatory.

  1. When using switch case
let myvariable = '';
passed  = 'b';
switch ( passed ) {
    case 'a':
        myvariable = 1;
    break;
    case 'b':
        myvariable = 2;
    break;
    default:
        myvariable = 3;
    break;
}
console.log(foo);
  1. When using if else
let passed = '';
if ( passed === 'a' )
    myvariable = 1;
else if ( passed === 'b' )
    myvariable = 2;
else
    myvariable = 3;
  1. For n numbers of condition ternary is not right and also confusing

Then Solution is objectLiteral

let myvariable = ( {
    a: 1,
    b: 2,
} )[ 'passed' ] || 3;

Or

let myvariable = {
    a: 1,
    b: 2,
};
let foo = values[ 'passed' ] || 3;

Performance are high to low.

a) Switch and objectLiteral around same(high) b) ifelse(low)

About

This is a demo show you how you can increase performance of js application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages