Boost Your Javascript Knowledge-Part2
There are two types of Javascript data.
- Primitive data type
- Reference data type
Primitive Data Type:
Primitive data types deal with values it has no concern about variable addresses. they are number, string, boolean.
let's see an example:
let a = 5 — — an address will be created to store a
let b= a — — an address will be created to store b, but the address of a will remain the same.
a = 20 — — the value of a has-been changed
console.log(b) — — — 5
console.log(a) — — — 20
Reference Data Type:
The reference data type deals with the addresses of the variables.
they are array and object.
Let’s see an example :
let arr = [ 1, 2, 3, 4]
let newArr = arr — — here the addresses for newArr and arr are the same.arr
arr[0] = 5 ;
console.log(arr) — — [ 5, 2, 3, 4]
console.log(newArr) — — [ 5, 2, 3, 4]
typeOf():
This method is used for knowing the data types. I am sharing some examples so that you can understand the data type of any data.
Error Handling:
try{}:
any coding error inside try does not bother any code.
catch{}:
the catch will capture the error inside the try block and then it will store that error and print it as a normal text.
let’s see an example:
try {
test();
}catch(err){
console.log(err) — — ReferenceError : test is not defined
}
here, test function is not defined so there will be an error. catch will capture that error and will print as a normal text in the console.
finally{}:
whether there will be an error or not inside try-catch, the code inside finally will run successfully
try {
test();
}catch(err){
console.log(err) — — ReferenceError : test is not defined
}finally {
alert(“Inside finally’’)
}
Javascript comments:
comments are used to give info about the code and it won’t run as a code. It will remain in the code editor and only the developer will see that comments.
It is a good practice of writing comments.
there are two types of comments.
- single-line comment:
a single-line comment is written after this //
//……….
2. multiline comment:
/* */ multiline comments are written inside this.
/*……..*/
What Is Cross Browing?:
Cross Browing:
It’s a test of making sure that your website is working across an acceptable number of web browsers. as a developer, it is your responsibility to test it.
Besides, as a developer, you should imagine yourself as a user to feel the test of using your website.
Coding Style:
coding style:
It is really a fact that how you solve any problem by coding. It is necessary to clean your code and try to make your code better readable. this is an art that makes you a better programmer. If your code is clean and easy to read then you have gained the art of programming skill.
I have some suggestions that will make your code more readable. I have gained those techniques on the internet.
- always give spaces between parameters
- to give spaces between operators.
- indentation is required for better code readability.
- curly braces on the same line should be neglected
- Do not repeat your code
- an empty line should be avoided.
Introduction to asynchronous programming:
This is a data transmission method where data is sent without loading and you can do any task without getting bored and it is used when the server takes time to finish its task.
characteristics of async :
- half-duplex type transmission
- start and stop bits are added with data for security
- data is sent in the form of byte or character
- data transmission is slow
- no loading no need to wait