2

Day 8 : Learning JS Fundamentals, Part-2

 3 years ago
source link: https://dev.to/gauravshekhawat/day-8-learning-js-fundamentals-part-2-4nll
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for Day 8 : Learning JS Fundamentals, Part-2

Day 8 : Learning JS Fundamentals, Part-2

Aug 21

・2 min read

see the below example:-

In the function above, we have not declared the variables teacher and topic, still we assigned them values. When we call this function, this changes the value of the "teacher" variable present in the global , while the topic will be declared as a new variable in the global scope, hence the output of the last line will be "React".


Undefined vs Undeclared

clear from the name...


function expressions

Function expression

Arrow function Expressions

just skim through the above two articles starting paragrpahs.


The first function above is an example of anonymous function expression while the second is a named function expression.

Example for arrow functions:-


Immediately invoked function expressions

These are used in places of our code where we need to collect a set of variables and protect them from encroaching upon an outer scope. These are not used nowadays, instead block scoping is used(with let).

Block scoping

In the below example, the variable temp will be available only inside the if block.

var are good, when you want to define a variable at a function level. (as the scope of var is global or the function in which it is defined).


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK