Top 10 JavaScript Shorthands for Beginners in 2021

Hello friends, how are you all? Hopefully better. Today I will talk about Top 10 JavaScript Shorthands for Beginners. So before going into details, let’s know some information about it which will help us to understand the main point.

JavaScript is a powerful programming language that allows you to solve complex problems in the blink of an eye. Not only this, with the help of this program you can do even the smallest animation. And JavaScript’s job is not just to create any program. Explaining many programs is an important task. Even those who are proficient in JavaScript are called those who can understand its codes. It makes one proficient in both programming and web design.

I was introduced to JavaScript a long time ago. Then in the Sudoku Milano’s game solution was found and he got acquainted with JavaScript. Then I would send the sudoku of the magazine in java script by SMS. The answer would have been correct but unfortunately never won as a winner. Not only this, with the help of JavaScript many problems of engineering can be solved. And with the mouse pointer you can create a lot of fun things in JavaScript. So today I will talk about that JavaScript.

This tune is for those of you who have just started learning JavaScript programming. When it comes to learning any programming in the beginning, we follow a lot more rules and regulations. So as not to be mistaken. It is of course important. But the biggest advantage of programming is that you can do the same thing in many ways. So many people are looking for a shortcut to programming or writing more scripts by hand. And yes, even if there is such a short road. Today I will talk about some such issues. Today we will show you how to save time in JavaScript and use some known shorthand scripts.

So let’s see Top 10 JavaScript Shorthands for Beginners.

Top 10 JavaScript Shorthands for Beginners in 2021
Top 10 JavaScript Shorthands for Beginners

1. Decimal number

If you are going to work as a developer of a bank or financial institution then you must face this issue. Suppose you have to write tens of millions in numbers. So how do you write? You write 1 and give eight zeros. Is that so? But you can do this in JavaScript more easily. So, Just type ‘1e8’ and the program will understand that there will be eight zeros after one.

Thus, if you have to write 28000 in the program, you will only write 28e3. This means 3 zeros after 28. You can see below how to write in the code. It will very easy for you to understand. Both shorthand and longhand are shown.

/ * Shorthand * /

var myVar = 1e8;

/ * Longhand * /

var myVar = 100000000;

2. Increase or decrease the value

In order to increase the value of something, you usually have to specify everything in programming. For example: to add 1 to i, type

i = i + 1;

But JavaScript also has a short form. This can be done very easily using only two plus (+) symbols.

That is, in that case you have to write,

i +;

Similarly, when we subtract 1 from j, we usually write,

j = j-1;

But you can write this in a nutshell,

j-;

You can see below how to write in the code. Both shorthand and longhand are shown.

/ * Shorthand * /

i +;

j-;

/ * Longhand * /

i = i + 1;

j = j-1;

However it is not commonly used. It is used only when there is a loop function in a program.

3. Addition, subtraction, multiplication, division

There are also some abbreviated forms of JavaScript for addition, subtraction, multiplication and division. And it’s like raising or lowering the general value.

Suppose 5 is added to a variable i, 3 ​​is subtracted from j, 10 is multiplied by k or 2 is divided by l. In that case you can use the abbreviations as below. Both shorthand and longhand are shown.

/ * Shorthand * /

i + = 5;

j- = 3;

k * = 10;

l / = 2;

/ * Longhand * /

i = i + 5;

j = j-3;

k = k * 10;

l = l / 2;

4. Adjust character position

CharAt () is a very popular method of stringing, it fixes the position of any character. It also has some shorthand for ease of work. Those who work hard at it will understand better. See below what will happen to both shorthand and longhand.

var myString = “Happy birthday”;

/ * Shorthand * /

myString [4];

/ * Longhand * /

myString.charAt (4);

5. Declare many variables

Top 10 JavaScript Shorthands for Beginners in 2021
Top 10 JavaScript Shorthands for Beginners

If you want to declare more than one variable at a time, you do not need to type those variables repeatedly. Just type var () and put them in brackets. You can understand better by looking below. Both shorthand and longhand are shown.

/ * Shorthand * /

var i, j = 5, k = “Good morning”, l, m = false;

/ * Longhand * /

Var i;

Var j = 5;

var k = “Good morning”;

Var l;

and var m = false;

This allows you to set both defined and undefined variables.

6. Declare an array

Declaring an array is a fun JavaScript job, for example,

var myArray = [“apple”, “pear”, “orange”]

However, placing an array every time is quite a hassle. So you can do array work like below without mentioning it again and again.

Below are the names of famous people and their place of birth through myArray. Both shorthand and longhand are shown.

/ * Shorthand * /

var myArray =

  “Grace Kelly”: “Philadelphia”,

  “Clint Eastwood”: “San Francisco”,

  “Humphrey Bogart”: “New York City”,

  “Sophia Loren”: “Rome”,

  “Ingrid Bergman”: “Stockholm”

}

/ * Longhand * /

var myArray = new Array ();

myArray [“Grace Kelly”] = “Philadelphia”;

myArray [“Clint Eastwood”] = “San Francisco”;

myArray [“Humphrey Bogart”] = “New York City”;

myArray [“Sophia Loren”] = “Rome”;

myArray [“Ingrid Bergman”] = “Stockholm”;

7. Declare the object

The process of declaring an object is exactly the same as declaring an array. So you can understand about its use by looking below. Both shorthand and longhand are shown.

/ * Shorthand * /

var myObj = {name: “Sean Connery”, placeOfBirth: “Edinburgh”,

age: 86, wasJamesBond: true;

/ * Longhand * /

var myObj = new Object ();

myObj.name = “Sean Connery”;

myObj.placeOfBirth = “Edinburgh”;

myObj.age = 86;

myObj.wasJamesBond = true;

8. Using conditional operator

Conditional operators are usually used in any programming. It has 3 main parts.

  •  The first condition
  • Then there is what happens if the condition is true
  • Then the condition is false or what happens in other cases
Top 10 JavaScript Shorthands for Beginners in 2021
Top 10 JavaScript Shorthands for Beginners

However, in JavaScript you can also use it in short form i.e. shorthand. See below.

The following example shows a code for selecting adults in a club. No one under the age of 18 can join. Both shorthand and longhand are shown.

var age = 17;

/ * Shorthand * /

var message = age> = 18? “Allowed”: “Denied”;

/ * Longhand * /

if (age> = 18)

  var message = “Allowed”;

} else

  var message = “Denied”;

}

9. Check the presence of variables

Sometimes you may need to know if there is a specific variable in the data.

If you look at the example below, you will understand how easy it is to cross things out in shorthand. But let me say one important thing. Never give up longhand writing while writing in shorthand. Because, many programs are difficult to understand if you do not practice longhard writing. See below. Both shorthand and longhand are shown.

var myVar = 99;

/ * Shorthand * /

if (myVar)

  console.log (“The myVar variable is defined AND it’s not empty.”

  AND not null AND not false. “);

}

/ * Longhand * /

if (typeof myVar! = “undefined” && myVar! = “” && myVar! = null

&& myVar! = 0 && myVar! = false)

  console.log (“The myVar variable is defined AND it’s not empty.”

  AND not null AND not false. “);

}

10. Checking the absence of variables

The absence of a variable can be checked as before by simply placing an exclamation mark before ‘My Variable’. See below. Both shorthand and longhand are shown.

var myVar;

/ * Shorthand * /

if (! myVar)

  console.warn (“The myVar variable is undefined (OR) empty (OR)

  null (OR) false. “);

}

/ * Longhand * /

if (typeof myVar = “undefined” | myVar = “” | myVar = null.

| myVar = 0 | myVar = false)

  console.warn (“The myVar variable is undefined (OR) empty (OR)

  null (OR) false. “);

}

The most important thing is that in no way can the practice of longhand abandon. Shorthand only for special use. And anything needs to take root. So it is better not to use shorthand without special needs.

There will always be new knowledge. Know the unknown. But yes. Don’t just sit there knowing. Spread this knowledge to those to whom these tunes cannot reach. Although Knowledge is not a thing to keep to oneself. So, Spread the word among everyone who is around. Love technology, stay with technology.

So far as today. But, I will appear again in the future with any new information. And don’t forget to let us know what the tune looked like

Leave a Comment