Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Shorthand variable assignment:
- // A)
- // if all variables are being assigned equal values:
- // instead of this
- var a = 1;
- var b = 1;
- var c = 1;
- // do this
- var a = b = c = 1;
- // first c is set to 1
- // then b is set to c as c = 1 and same goes with a
- /***************************************************************************************************************************************/
- // How ever this is not a recommended way to assign variables. Because we haven't declared variables b and c because of which they won't be locally scoped to the current block of code.
- // Both will be globally scoped and end up polluting the global namespace.
- // B)
- // instead of
- var d = 2;
- var e = 5;
- var f = 8;
- // do this
- var d = 2, e = 5, f = 8; // OR
- var d = 2,
- e = 5,
- f = 8;
- // all three variables i.e d, e, and f are locally scoped.
Add Comment
Please, Sign In to add comment