Javascript’s Interesting Things

Minhajul Abedin Rahat
4 min readMay 6, 2021

1.Global Scope

Global scope means that if you declare any variable using var and outside of any block, then you can access that variable from anywhere in your code.

.2 Local Scope

Local scope means if you declare any variable inside any function, you don’t use that function outside of that function. If you want to use that local variable, you have to use it inside the function.

We can see that we can’t access the local variable from the outside of that function.

3. Function Scoped

In a function block, you can access variables from everywhere inside your function.

But you can’t access any variable which declares the inside function block from the outside of the function block.

4.Block Scoped

In function scoped, we saw that if we declare the same name variable in a different condition block using Var, we can access those variables inside the function block, .but as a programmer, this is really annoying because it messes up sometimes. To avoid this problem in javascript, we use to let that help us to overcome that problem.

Function Scoped

And the solution using Let make that variable blocked scoped.

5.Hoisting

Hoisting means pulling the variable to the top. Let’s see on the code.

But if we change our code, we use console log before the declaration of hostingTest Then on that time, and the engine does one thing it cut the var and take a name like hostingTest in top & set it as a var variable but do not assign any value for that it trow undefined error.

but again, we use console log after assign the hostingTest variable, and it will give the output

so get rid of this problem. javaScript provides us let and const variable.

6.Try-Catch

we know that in the javascript compiler, read the code line by line. If it’s got an error, it will stop in that place. Don’t move forward, so handle this error we should know about try-catch . Which is an error handling method. Try-catch uses for runtime error, not for the syntax error.

We can see that when that code finds an undefined variable, it was stoped, not move forward from the second line. So we want that handle this error and run the full code after getting the error and also get the message for which reason we got this error for that we can use try-catch

So we can see after getting the error, the compiler moves forward 7 what kind of error occurred. We can check that.

Inside the catch function, you have to set a parameter, and it can err, error whatever you want. Using that if you want to see only error name, you will use

console.log(err. name)

or, if you want to see the error message, you have to use

console.log(err. message)

7.Finally

If you want to show something to your user, whatever there is any error o occurred or not. So do that thing after using try-catch

8.Cross Browsing Testing

Cross browsing testing means ensuring that your web project or app works properly in an acceptable number of browsers, devices, whatever it’s, .so that users can get more satisfaction from your site or app. If your site is working well in your browser like chrome, this is your responsibility to ensure that your site works properly in another browser like opera, safari, Mozilla as same as yours.

9.Reasons why happed cross browsing issues

I.Some times the browser application has bugs.

II.Different browsers use different technology.

III.Incorrect Doctype

IV.No Reset CSS

V.Invalid HTML/CSS

10.Spread Operator

The spread operator is the most useful thing in JS. You can compare it with concat. It’s basically used on an array. It uses using three-dot(…). After using that, you can merge a new element with your existing array.

Normal Concat Method

Spread operator doing the concat job

That’s it for today we will meet very soon with some new interesting things.

--

--

Minhajul Abedin Rahat
0 Followers

I'm so ambitious & determined about my goal & strongly believes in positivity.