10 Things About JavaScript you Must Need To Know.

1. Truthy Value:

‘string’ :- All the strings are True other then empty string;

Number:- All the Numbers are True other then 0;

[] :- All the arrays are True;

{} :- All the objects are False;

2. Falsy Value:

0 :- Zero is a Flase value;

‘’ (Empty string):- Empty string is a False value;

nul:- Nul is a False value;

NaN (Not a Number):- Nan is a False value;

Undefined:- Undefind is a False value;

3. Nul vs Undefined:

Undefined:-

If you do not set the value of any variable the value would be undefined

If you set an undefined value the value would be undefined.

If you do not return the function the value would be undefined

If you do not pass the parameter the value would be undefined.

Nul:-

Nul means empty or not existence. So if you want to set the value as empty or not existence you can set Nul.

4. Dubble Equal “==” vs Tripple Equal “===” :

Dubble Equal: Dubble equal just check the value not type;

Tripple Equal: Tripple equal check the value with type

5.Scope:

  • Local Scope:- If you declare a variable in a function, you can not call the variable from outside of the function.
  • Global Scope:- If you declare a variable outside of a function, you call the variable from anywhere.
  • Hoisting:- If you declare a variable as a var in scope you can access this variable from anywhere but if you declare a variable as a let or const you can not access the value from the scope.

6. Closure:

If you create a function in a function it creates a close environment. And the inner function accesses the variable from outside the function and when you call the function multiple time as different variable every variable keep individual value and create a close environment.

7. What is DOM:

DOM means document object model. When a web page is loaded, the browser creates a Document Object Model of the page. And if we want to change, modify, or add something then JavaScript can access and change all the elements of an HTML document in real-time.

8. What is Javascript:

Javascript is a single-threaded, interpreted, or just-in-time compiled programming language. It is also a client-side programing language of browser but exceptionally you can use it in the backend site using node js.

9. How Javascript works:

JavaScript is a client-side programing language and one of the most efficient and commonly used scripting languages. It runs at the client-side inside the web-browsers, but one important thing is that the client’s web browser also needs to support JavaScript. Most of the modern web browsers support JavaScript and have their JavaScript engines. Like,

Google Chrome has its own JavaScript engine called V8.

Edge has its own JavaScript engine called Chakra.

SafariJava has its own JavaScript engine called Script Core

Firefox has its own JavaScript engine called Spidermonkey

10. How to sum all the numbers in an array:

First of all, you have to create an array and a variable for sum. Then you must throw a loop and finally add the elements with the variable. For example:

var numbers = [20, 25, 30, 35, 40];

var sum = 0;

for(var i = 0; I <numbers.length; i++){

var element = numbers[i];

sum = sum + element;

}

console.log(‘total’, sum);