RE: Let's get back to basics - JavaScript by sn0n

View this thread on steempeak.com

Viewing a response to: @boyanpro/let-s-get-back-to-basics-javascript

· @sn0n ·
Iono man, let & const should be used when use strict is on... Right? 
๐Ÿ‘  
properties (23)
post_id75,098,251
authorsn0n
permlinkre-boyanpro-let-s-get-back-to-basics-javascript-20190521t113403861z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steempeak\/1.9.9"}
created2019-05-21 11:34:06
last_update2019-05-21 11:34:06
depth1
children1
net_rshares28,569,317,528
last_payout2019-05-28 11:34:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length69
author_reputation8,066,156,921,766
root_title"Let's get back to basics - JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@boyanpro ·
Not necessarily.

While `"use strict"` came in ES5 and `let`+`const` came later with ES6 what is worth remembering is that `var`, `let` and `const` have different features and that then means different usages. `let` and `const` don't make `var` obsolete, they make it less powerful.

Here are more details about `const`, `let` and `var`:

- `const` is a signal that the identifier wonโ€™t be reassigned.

- `let`, is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block itโ€™s defined in, which is not always the entire containing function. 
- `var` is now the weakest signal available when you define a variable in JavaScript. The variable may or may not be reassigned, and the variable may or may not be used for an entire function, or just for the purpose of a block or loop.

In other words here are differences between these three:
- `var` declarations are globally scoped or function scoped while `let` and `const` are block scoped.
- `var` variables can be updated and re-declared within its scope; `let` variables can be updated but not re-declared; `const` variables can neither be updated nor re-declared.
- They are all hoisted to the top of their scope but while `var` variables are initialized with undefined, `let` and `const` variables are not initialized.
- While `var` and `let` can be declared without being initialized, `const` must be initialized during declaration.

Here are w3schools page explaining "use strict": https://www.w3schools.com/js/js_strict.asp

I hope my explanation was helpful. Cheers!

๐Ÿ‘  
properties (23)
post_id75,105,274
authorboyanpro
permlinkre-sn0n-re-boyanpro-let-s-get-back-to-basics-javascript-20190521t142230067z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steempeak\/1.9.9"}
created2019-05-21 14:22:30
last_update2019-05-21 14:22:30
depth2
children0
net_rshares28,066,126,626
last_payout2019-05-28 14:22:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,641
author_reputation1,773,735,625,367
root_title"Let's get back to basics - JavaScript"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)