Javascript Fundamentals You need to know.

1.start with primitive types of javascript:

There are 7 primitive data types in javascript. These are string, number, bigint, boolean, undefined, symbol, and null.

Now, what is meant by primitive type? A primitive type is those values that you can’t alter directly. If you want to change a value of the primitive type, you have to reassign a new value.

Here what you can do with primitive value and what can’t

2.Object and function values:

object and function are not primitive types of values because we can alter them directly from the code. Let's say you made an array that has a list of five friend’s names. After a few days later, you got to new friends and want to add to the list? What will you do? An array is an object so that you can alter it directly. Below is the code that explains how you can add those two friends directly to the previous array.

3.Javascript Expression:

It’s one of the core things of every programming language. It gives life to the language. Expression takes two or more values. After that, it processed those values and returns them as a single value.

below are the example of javascript expression

4. Type Of:

One more basic and interesting thing about javascript is typeof. It checks the type of input given by the user or written by the developer. It has many practical uses; one of them is input field validation. If a user mistakenly puts a field empty or gives a different type of value, we can find the user to give the correct type of value.

Example: User asked to give his/her age in the input field, but user mistakenly gave his name on that field! Here name is string type and age is number type, in that case, we can give an alert to the user to give the correct value, and as long as the user didn’t give the correct value code will keep asking the user to give the right value,

Example in code:

5. Try-Catch(lifesaver)

It doesn’t matter how you are in programming; you can’t guarantee that your code will not throw an error. It happens for many reasons such as wrong code, wrong user response or failure to connect with database, etc.

When code gives errors, try-catch helps to give the error feedback instead of killing the code.

Three things you should know about try and catch

  1. It executes in runtimes only.
  2. It can't solve syntactical errors.
  3. It can’t solve a code if it’s scheduled.

below is an example of try-catch

6. Cross browsing testing:

it’s important that a developer will run a cross browsing test for his codebase. Because there is some difference from one browser to another and older version browser to newer, If a website can’t run in most of the browser then it’s not really practical.

Now Should you have to test for all of the browsers that exist? No, absolutely not because there are hundreds of thousands of browsers available on the internet and you can’t test for all of them. What you can do is you can test for a few common browsers to test the code.

7. Spread operator (Magical one):

Spread operator helps to copy a whole array or object and then add one or more value with it easily. It’s used most of the time when we want to add value to an object.


8.Block-level element, var variable!

var is a flexible variable in javascript, it’s a leaker variable means, it can leak its value from block-level element to the global stage which can cause changing of global value.


9. Block-level element, const variable:

As we know const is a strict type, we can’t redeclare one const again. But at the block level, we know that the block-level element doesn't give value outside of the scope or make conflict with a global variable. So we can redeclare a const variable in global and local scope simultaneously


10.Block-level element, let variable!

let is a flexible variable in javascript, it doesn’t leak its scope value to the global variable. And it’s not a strict type so we can redeclare the same variable again in block level and two of the let variable keep their own value.


Programming is the magic of new era