1599462121
Everyone knows that Javascript and Typescript have several weird and hidden features that allow you to shorten the amount of code you write. To preface this article, I’d like to impose upon you an important tidbit of information, short and efficient code doesn’t always equal good code. As always, you should be prioritizing readability over implementing a bunch of fancy features.
That being said, these features can help you save tons of space and used properly are easily understandable to anyone else who’s reading your code. Let’s go over some of these shorthand features so that you can use and understand them in your code.
This is probably the most well-known shorthand Javascript function, the shortened “if-else” statement. By using this operator, you can remove a lot of the if else
boilerplate and turn four lines into one!
let v = true;
// Traditional approach
if (v) {
console.log('True');
} else {
console.log('False');
}
// Ternary Operator
v ? console.log('True') : console.log('False');
The structure is as follows: <conditional expression> ? <true case> : <false case?
. Pretty simple, right? This is a great way to do one line if else operations and is especially useful when combined with other shorthand operators.
This one is particularly for Typescript (Sorry vanilla JS users), but is a great feature when building classes.
Normally in a class, you have to list all your class variables then reassign them in your constructor, which takes tons of lines of code. But if your class is relatively simple (you’re just assigning parameters to private variables), Typescript has a great way to cut the amount of code you write.
// Normal way
class Location {
private _latitude: string;
private _longitude: string;
constructor(latitude: string, longitude: string) {
this._latitude = latitude;
this._longitude = longitude;
}
}
// Shorthand in TypeScript
class Location {
constructor(
private _latitude: string,
private _longitude: string
) {}
}
On larger classes with tons of properties, this can be a real lifesaver!
Often misunderstood, the nullish operator lets you easily evaluate an expression and check if it’s null, and return a default value if it is null.
function nullish(value1, value2) {
// If value1 is null returns 'default'
let v1 = value1 ?? 'default';
return v1 + value2;
}
myFn("this has no") //returns "this has no default"
myFn("this has no", 0) //returns "this has no 0"
Actually, technically it checks for null
or undefined
, but the name is close enough. This is a great way to check if values exist or not.
ES6 simplified the process of assigning values to objects. If values are assigned to variables named exactly as the object’s properties, you won’t have to repeat the name!
let name: string = "Caelin";
let age: number = 18;
interface User {
name: string;
age: number;
}
// Old way (manual assignment)
let user1: User = {
name: name,
age: age,
}
// New way!
let user2: User = {
name,
age,
}
As shown above, the new way is considerably simpler and DRYer than the old way!
If you’ve seen a lot of these operators: =>
thrown around everywhere, they’re arrow functions. These allow you to save a return
statement since any lamda function will have a default return.
You’ll seen them often used in array operators as such:
let arr = [1, 2, 3, 4, 5];
// Long way
arr.map(function (n) {
return n*2;
})
// Short way
arr.map(n => n*2);
As you can see, it makes the code considerably more readable and shorter.
ES6 now allows you to specify default parameter values on functions! Before, you’d have to rely on OR’s lazy evaluation, which worked but was a suboptimal solution.
// Assigns 'c' a default value
function defaultParams(a, b, c="c") {
return a + b + c;
}
Fun tip, if you want to make a required parameter, do the following:
const requiredParam = _ => throw new Error('Required Parameter!');
// Create a default parameter d
function defaultParamRequired(a, b, c="c", d=requiredParam()) {
// Logic
}
Now, if this function runs without passing a default parameter d in, it’ll throw an error! Pretty cool trick right?
I literally wrote a whole article on spread operators, but spread and destructing operations are great ways to take advantage of objects and arrays!
It’s quite common to want to access object parameters individually (to modify or read them) without accessing the original object. Normally, this would require a line for each object parameter, which can get quite long on larger objects. Object destructuring allows us to cut that into one line!
const user = {
name: 'Caelin',
age: 18,
}
// Normal method
const name = user.name;
const age = user.age;
// Destructuring method
const {name, age} = user;
This syntax is great for object parameters and import statements to reduce the number of lines when dealing with complex objects.
Spread operators make it easier to combine objects and arrays by expanding them.
const arr1 = [1,2,3,4]
const arr2 = [5,6,7]
const finalArr = [...arr1, ...arr2] // [1,2,3,4,5,6,7]
const partialObj1 = {
name: "fernando"
}
const partialObj2 = {
age:37
}
const fullObj = { ...partialObj1, ...partialObj2 } // {name: "fernando", age: 37}
These are just a few of the many Javascript and Typescript shortcuts that can save you time and make your code cleaner. Remember, this is not simply about making code more efficient or reducing lines, it’s about making code that’s cleaner and easier to read for the next developer.
Did I miss something? Be sure to comment it down below!
There’s a lot of content out there, I appreciate you reading mine. I’m a young entrepreneur and I write about software development and my experience running companies.
Originally published on Medium.com
#web-development #typescript #javascript
1647351133
Minimum educational required – 10+2 passed in any stream from a recognized board.
The age limit is 18 to 25 years. It may differ from one airline to another!
Physical and Medical standards –
You can become an air hostess if you meet certain criteria, such as a minimum educational level, an age limit, language ability, and physical characteristics.
As can be seen from the preceding information, a 10+2 pass is the minimal educational need for becoming an air hostess in India. So, if you have a 10+2 certificate from a recognized board, you are qualified to apply for an interview for air hostess positions!
You can still apply for this job if you have a higher qualification (such as a Bachelor's or Master's Degree).
So That I may recommend, joining Special Personality development courses, a learning gallery that offers aviation industry courses by AEROFLY INTERNATIONAL AVIATION ACADEMY in CHANDIGARH. They provide extra sessions included in the course and conduct the entire course in 6 months covering all topics at an affordable pricing structure. They pay particular attention to each and every aspirant and prepare them according to airline criteria. So be a part of it and give your aspirations So be a part of it and give your aspirations wings.
Read More: Safety and Emergency Procedures of Aviation || Operations of Travel and Hospitality Management || Intellectual Language and Interview Training || Premiere Coaching For Retail and Mass Communication || Introductory Cosmetology and Tress Styling || Aircraft Ground Personnel Competent Course
For more information:
Visit us at: https://aerofly.co.in
Phone : wa.me//+919988887551
Address: Aerofly International Aviation Academy, SCO 68, 4th Floor, Sector 17-D, Chandigarh, Pin 160017
Email: info@aerofly.co.in
#air hostess institute in Delhi,
#air hostess institute in Chandigarh,
#air hostess institute near me,
#best air hostess institute in India,
#air hostess institute,
#best air hostess institute in Delhi,
#air hostess institute in India,
#best air hostess institute in India,
#air hostess training institute fees,
#top 10 air hostess training institute in India,
#government air hostess training institute in India,
#best air hostess training institute in the world,
#air hostess training institute fees,
#cabin crew course fees,
#cabin crew course duration and fees,
#best cabin crew training institute in Delhi,
#cabin crew courses after 12th,
#best cabin crew training institute in Delhi,
#cabin crew training institute in Delhi,
#cabin crew training institute in India,
#cabin crew training institute near me,
#best cabin crew training institute in India,
#best cabin crew training institute in Delhi,
#best cabin crew training institute in the world,
#government cabin crew training institute
1654588030
TypeScript Deep Dive
I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack Overflow / DefinitelyTyped and general engagement with the TypeScript community. You can follow for updates and don't forget to ★ on GitHub 🌹
If you are here to read the book online get started.
Book is completely free so you can copy paste whatever you want without requiring permission. If you have a translation you want me to link here. Send a PR.
You can also download one of the Epub, Mobi, or PDF formats from the actions tab by clicking on the latest build run. You will find the files in the artifacts section.
All the amazing contributors 🌹
Share URL: https://basarat.gitbook.io/typescript/
Author: Basarat
Source Code: https://github.com/basarat/typescript-book/
License: View license
1646100180
Looping through an object by its keys is a common task for many #JavaScript developers. In this lesson we discuss why your assumptions can break when migrating your code to #TypeScript and a quick fix you can use if you trust you code completely 🌹
1616670795
It is said that a digital resource a business has must be interactive in nature, so the website or the business app should be interactive. How do you make the app interactive? With the use of JavaScript.
Does your business need an interactive website or app?
Hire Dedicated JavaScript Developer from WebClues Infotech as the developer we offer is highly skilled and expert in what they do. Our developers are collaborative in nature and work with complete transparency with the customers.
The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.
Get your business app with JavaScript
For more inquiry click here https://bit.ly/31eZyDZ
Book Free Interview: https://bit.ly/3dDShFg
#hire dedicated javascript developers #hire javascript developers #top javascript developers for hire #hire javascript developer #hire a freelancer for javascript developer #hire the best javascript developers
1599462121
Everyone knows that Javascript and Typescript have several weird and hidden features that allow you to shorten the amount of code you write. To preface this article, I’d like to impose upon you an important tidbit of information, short and efficient code doesn’t always equal good code. As always, you should be prioritizing readability over implementing a bunch of fancy features.
That being said, these features can help you save tons of space and used properly are easily understandable to anyone else who’s reading your code. Let’s go over some of these shorthand features so that you can use and understand them in your code.
This is probably the most well-known shorthand Javascript function, the shortened “if-else” statement. By using this operator, you can remove a lot of the if else
boilerplate and turn four lines into one!
let v = true;
// Traditional approach
if (v) {
console.log('True');
} else {
console.log('False');
}
// Ternary Operator
v ? console.log('True') : console.log('False');
The structure is as follows: <conditional expression> ? <true case> : <false case?
. Pretty simple, right? This is a great way to do one line if else operations and is especially useful when combined with other shorthand operators.
This one is particularly for Typescript (Sorry vanilla JS users), but is a great feature when building classes.
Normally in a class, you have to list all your class variables then reassign them in your constructor, which takes tons of lines of code. But if your class is relatively simple (you’re just assigning parameters to private variables), Typescript has a great way to cut the amount of code you write.
// Normal way
class Location {
private _latitude: string;
private _longitude: string;
constructor(latitude: string, longitude: string) {
this._latitude = latitude;
this._longitude = longitude;
}
}
// Shorthand in TypeScript
class Location {
constructor(
private _latitude: string,
private _longitude: string
) {}
}
On larger classes with tons of properties, this can be a real lifesaver!
Often misunderstood, the nullish operator lets you easily evaluate an expression and check if it’s null, and return a default value if it is null.
function nullish(value1, value2) {
// If value1 is null returns 'default'
let v1 = value1 ?? 'default';
return v1 + value2;
}
myFn("this has no") //returns "this has no default"
myFn("this has no", 0) //returns "this has no 0"
Actually, technically it checks for null
or undefined
, but the name is close enough. This is a great way to check if values exist or not.
ES6 simplified the process of assigning values to objects. If values are assigned to variables named exactly as the object’s properties, you won’t have to repeat the name!
let name: string = "Caelin";
let age: number = 18;
interface User {
name: string;
age: number;
}
// Old way (manual assignment)
let user1: User = {
name: name,
age: age,
}
// New way!
let user2: User = {
name,
age,
}
As shown above, the new way is considerably simpler and DRYer than the old way!
If you’ve seen a lot of these operators: =>
thrown around everywhere, they’re arrow functions. These allow you to save a return
statement since any lamda function will have a default return.
You’ll seen them often used in array operators as such:
let arr = [1, 2, 3, 4, 5];
// Long way
arr.map(function (n) {
return n*2;
})
// Short way
arr.map(n => n*2);
As you can see, it makes the code considerably more readable and shorter.
ES6 now allows you to specify default parameter values on functions! Before, you’d have to rely on OR’s lazy evaluation, which worked but was a suboptimal solution.
// Assigns 'c' a default value
function defaultParams(a, b, c="c") {
return a + b + c;
}
Fun tip, if you want to make a required parameter, do the following:
const requiredParam = _ => throw new Error('Required Parameter!');
// Create a default parameter d
function defaultParamRequired(a, b, c="c", d=requiredParam()) {
// Logic
}
Now, if this function runs without passing a default parameter d in, it’ll throw an error! Pretty cool trick right?
I literally wrote a whole article on spread operators, but spread and destructing operations are great ways to take advantage of objects and arrays!
It’s quite common to want to access object parameters individually (to modify or read them) without accessing the original object. Normally, this would require a line for each object parameter, which can get quite long on larger objects. Object destructuring allows us to cut that into one line!
const user = {
name: 'Caelin',
age: 18,
}
// Normal method
const name = user.name;
const age = user.age;
// Destructuring method
const {name, age} = user;
This syntax is great for object parameters and import statements to reduce the number of lines when dealing with complex objects.
Spread operators make it easier to combine objects and arrays by expanding them.
const arr1 = [1,2,3,4]
const arr2 = [5,6,7]
const finalArr = [...arr1, ...arr2] // [1,2,3,4,5,6,7]
const partialObj1 = {
name: "fernando"
}
const partialObj2 = {
age:37
}
const fullObj = { ...partialObj1, ...partialObj2 } // {name: "fernando", age: 37}
These are just a few of the many Javascript and Typescript shortcuts that can save you time and make your code cleaner. Remember, this is not simply about making code more efficient or reducing lines, it’s about making code that’s cleaner and easier to read for the next developer.
Did I miss something? Be sure to comment it down below!
There’s a lot of content out there, I appreciate you reading mine. I’m a young entrepreneur and I write about software development and my experience running companies.
Originally published on Medium.com
#web-development #typescript #javascript