10 Simple But Important Things Of JavaScript
Published: 2022-02-21 14:27:04

If you are a beginner, you should learn these 10 things which is very much. Let's start discussing.

## 1. Variables
JavaScript variables are containers for storing data values. There is 3 keyword to declaring variables in JS.

We can create variables using the ‘let’ and ‘const’ keywords. There are some restrictions. Because they are block scope variable.

```
let name = “Habibullah Bahar”;
const name = “Piash”;
```
Another way to create variable using the ‘var’ keyword. There is no such restriction.

```
var age = 20;
```
‘var’ and ‘let’ are reassignable. But, ‘const’ is not reassignable.

## 2. Operators
There are four types of operators in JavaScript.

- **Arithmetic Operators:** +, -, *, /, %, ++, —
- **Assignment operators:** =, +=, -=, *=, /=, %=
- **Comparison Operators:** ==, ===, !=, !== >, <, >=, <=
- **Logical Operators:** &&, ||, !

## 3. Data Types
**Primitive Data Types:** The Primitive Data types in JavaScript include Number, String, Boolean, Undefined, Null, and Symbol. JavaScript primitive data types are data types that refer to a single value.

```
E.g. var a =5;
```

Here the variable ‘a’ is an integer data type and has a single integer value. The variable ‘a’ refers to a single value in memory. If we want to change the value of a, we would have to assign a new value to a. Primitive data types are not mutable.

Here are Primitive Data Types:
- Number
- BigInt
- String
- Boolean
- Symbol (new in ES2015)
- null
- Undefined

**Non-Primitive Data Types:** The Non-Primitive data type has only one member, Object. Function, Array, Date, RegExp, etc. are objects.

Here are Non-Primitive Data Types:
- Object
- Function
- Array
- Date
- RegExp

## 4. Function
A JavaScript function is a block of code designed to perform a particular task and the code will be executed when it called. Function is re-useable. For calling a function, need to use parentheses(). Ex- function_name().

For creating a function, you need to use the ‘function’ keyword before function name.

```
function_name(){
....
}
```

You can also create arrow function:

```
const function_name = () => {
....
}
```

## 5. Events
Events are things that happen to HTML elements. JavaScripts can interact with those events when we use JavaScript in HTML.

Here are some common events:
- onclick
- onchange
- onload
- onkeyup

## 6. DOM (Document Object Model)
Javascript can add, remove & change all the elements, attributes & CSS styling. JS can create & react to all HTML events. (click,hover,keyup,keydown etc.) In the DOM, all HTML elements are defined as objects.

## 07. Error Handling
You have to know error handling when you write JS codes. In the new version of JavaScript, there are few ways to handle errors. Like, console.log, console. error, try…catch, etc.

## 08. Debugging
It is also important for a JavaScript developer. You have to learn how to identify & fix errors and bugs in your application. Most web browsers notify developer about errors but different browser shows errors in different ways.

## 09. Conditions
In **JavaScript**, there are few conditional statements. Use if to specify a block of code to be executed, if a specified condition is true.

**if(Condition){….}**: Use if to specify a block of code to be executed, if a specified condition is true.

**while(condition){….}**: If the condition is true then the code block will be executed and it will be executed until the condition is not false.

There are more conditional statements to write codes conditionally.

## 10. Form Validation
We can validate forms using JavaScript before sending data to the server. We can set a mandatory field or optional in JS.

Also, we can check that the data is in the right format, structure, or not.

We will discuss more in the other articles.

**My Portfolio Website**: [https://habibullahftl.web.app/](https://habibullahftl.web.app/)