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.
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.
4. Type Of:
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:
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
- It executes in runtimes only.
- It can't solve syntactical errors.
- 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!
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!