UrbanPro

Learn Java Script Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why do people prefer TypeScript with most of the JavaScript frameworks?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

IT Professional Trainer with 15 years of experience in IT Industry

Absolutely. var behaves differently from let and const, and it’s reasonable to think you may need that behavior. For me, this has become more pertinent with my growing usage of async/await. Take the following code. getData(userID) .then( (userProfile) => { return userProfile.name } ).catch(...
read more


Absolutely. var behaves differently from let and const, and it’s reasonable to think you may need that behavior. For me, this has become more pertinent with my growing usage of async/await.

Take the following code.

getData(userID)
.then( (userProfile) => {
return userProfile.name }
).catch( (err) => {
log.error(`Hit a snag: ${err}`);
})
This is the standard promise flow. But async functions allow a more recognizable synchronous flow.

let userName = await getUserName(userID);
But wait! There’s not error handling in this! That’s ok, because this is now good, old-fashioned synchronous JavaScript. We can just use a try/catch!

try {
let userName = await getUserName(userID);
} catch(err) {
log.error(`Hit a snag: ${err}`);
}
Only, this won’t work. Both let and const are block-scoped, and a try statement is a block scope. the variable userName won’t be available outside of that try block.

Best practices dictate pre-declaration of variables to the block in which they will be used, like so:

let userName;
try {
userName = await getUserName(userID);
} catch(err) {
log.error(`Hit a snag: ${err}`);
}
I find that ugly, though, especially if you are getting a whole bunch of async variables. I don’t want to write a stack of variables then define the same stack later on. I find it much easier to take advantage of var’s function scoping and both declare and define variables within the try block.

That is only one example that I encounter frequently. Again, because var behaves differently, if you desire that different behavior, use it! Don’t only use let and const because of some bizarre dogma promulgated by people who barely know fizz-buzz.

read less
Comments

Related Questions

Want to learn javascript jquery and angular with live demo
Yes you can join me, i will provide you teaching with real life example,
Sandeep
0 0
7
How to learn Javascript?
I would say, https://developer.mozilla.org/en-US/docs/Learn/JavaScript is the best place to learn if you want real good knowledge in Javascript. Have a little bit patience and put some effort in learning...
Ramya
Should I learn Python or JavaScript as a newbie?
Python is different from javascript. I prefer you go with python as it is in boom now.
Manisha
0 0
6

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Always keep learning
If you are in IT, in order to survive you have keep reading and keep polishing your skillsets and this you can do everyday by taking small steps like learning and implementing them. There are so many...

Web Technology Tutorial
Web Technology has 2 category Front End (HTML,CSS,JS Etc) Back End/Server Side (PHP,JSP,ASP,ROR Etc) Front End technologies are - HTML, CSS, Bootstrap, Javascript, jQuery etc. Using front end...

NgModules vs. JavaScript modules (Angular 2)
The NgModule — a class decorated with @NgModule Decorator — is a fundamental feature of Angular. JavaScript also has its own module system for managing collections of JavaScript objects. It's...

Angular 1 vs Angular 2
Angular team has released the angular 2, which has drastically change the way programmers interact and work with Angular framework in the past. In this post I will tell you the common changes made by...

Simple Algorithms - Fibonacci, Finding GCD & Finding LCM.
import java.util.Scanner; //0,1,1,2,3,5,8,13,21,34... //fun(n)=fun(n-1)+fun(n-2) where n>=2 /*fib(9)=fib(8)+fib(7) =fib(7)+fib(6)+fib(6)+fib(5) =fib(6)+fib(5)+fib(5)+fib(4)+fib(5)+fib(4)+fib(4)+fib(3) */ public...

Recommended Articles

Here are the top 6 must have skills for every Web Designer : Technical Skills Web designers undoubtedly require very strong technical skills. They must have hands on using Web designing software and tools, such as Adobe Dreamweaver, Fireworks, Photoshop, Flash etc. In addition to the knowledge of design...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Looking for Java Script Training classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Script Training Classes?

The best tutors for Java Script Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Script Training with the Best Tutors

The best Tutors for Java Script Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more