Some interview question in JavaScript
What is JavaScript
For interactive our website we uses some scripts, its JavaScript.
JavaScript is a lightweight, single-threaded, just-in-time compiled programming language. While it is the most well-known scripting language for Web pages, many non-browser environments also use it, such as Node.js
JavaScript is front-end or back-end or client-side or server-side
JavaScript is client-side, but in some ways it also run in back-end. Its called Node.
How works JavaScript
There is a thing named V8, who execute JavaScript just-in-time compile then give the output.
Truthy and Falsy
🟢All number is truthy other then 0. 🟢All string is truthy other then empty string. 🟢Empty Array and Empty String both are Truthy.
🔴Undefined, Null, and NaN (Not a Number) values are false. 🔴If variable set by false, it is falsy.
Undefined VS Null
Undefined is Negative or falsy
Null means not exists
🟢Value is not set. 🟢If function is not return or return but not said what is returned. 🟢If parameter is not pass. 🟢If property is not set in object 🟢If value is set undefined
Double equal (==) vs Triple equal (===)
Double equal (==) just check value. Triple equal (===) check value and type.
Closure
If you call/return one function from another function, it will create a close environment. Then if you return/use second or inner function it will create close environment and keep external variable reference.
Bubble Event
Propagating an event from the lowest to the upward. When any event happed on an element, first of all it runs the handlers on it. Then it runs its parent. Then it run all the way up on other ancestors.
Recursive vs Iteration function
Recursive Function: If any function is called itself this is called recursive function.
DOM
DOM means Documents Object Model. When it see any HTML file, it ready this file as a JavaScript object. So that, if we can access or modify it next time we can easily access or modify it in real-time.
Callback function
When a function passed to another function as a parameter is called callback function. A callback function can run after another function has finished.
Get vs Post
Get: Get means data get. It send data by url. Its limit is 2048 character.
Post: For to submission data server send a request its post. Normally all request send in body. It has no limit.