DEV Community

Taieb Hossain
Taieb Hossain

Posted on

Tricky Javascript

  1. Null vs Undefined: At first everyone thinks that null and undefined are the same. But this is not true they are totally different. Undefined means something that declared but the value is not assigned then it will show you undefined. On the other hand, null should be assigned to null. It means nothing or empty.

  2. Double (==) and Tripple (===): These are used in the conditional comparison. Double == checks only the value is the same or not if so that returned true, but === not only checks the value also the type of the value.

  3. Scope: Scope means accessible area. If you declare a variable in a function that can't be accessible in the outer function, this is called function scope. In ES6 let/const are blocked scope variables. It means if you declare a variable with let or const inside a {} that variable is in the block scope, you can't access outside of the {}. This is called block scope.

  4. Arrow function: In 2015 Javascript ES6 was released. The arrow function is one of the new addition in es6. The arrow function is the alternative to the traditional function declaration. It is short and useful. Example:

regular function :
function add(x, y){
return x + y
}
arrow function : const add = (x, y) => x + y;

  1. What is javascript and its features: Javascript is a scripting language focused on the client-side to interact with the users on the webpage. It has tons of features, I think it is one of the most growing languages in the world.
    i) Lightweight: javascript is lightweight and too fast to interact on the client-side.
    ii) Object-based: Javascript is an object-based language, which means users have more control.
    iii) Functional: It is possible to write javascript in a functional way.
    iv)Interpreted language: Javascript is an interpreted language. The code written by javascript is processed line by line.
    v)Async: Asynchronous means nonblocking. Javascript works mainly in a synchronous way top to bottom one by one. but it is possible to write javascript code asynchronously.

  2. How javascript code executes: Javascript is a scripting language runs on the browser. It has no compilation step. It means browsers has interpreters that reads the js code top to bottom and interprets it and then run the code.

  3. DOM: DOM means (Document Object Model). A whole webpage is a document. It has various small parts. You can access all the small piece of document of any page with DOM.

  4. Callback function: Callack function is function that is passed to the another function as a parameter. It is also called higher order function. We know that javascript is a single threaded programming language, it can only do one task at a time but some time we need to run code after a task was completed. It is not possible with js normal behaviour that's why we need callback function. Example:

const total = (callback) =>{
callback()
}

cosnt callback = (x, y) => {
return x + y;
}

  1. Let/Const: Let/Const are the new addition of javascript declaring a variable. Before these var is the one and only to decalre a variable. Let has block scope. Declare a variable with let can't be accessed outside of the scope it declared. And Const is constant, if you declare a variable with const you can't change the variable in future.
    Declared an array with const is mutable but not reassignable

  2. API: API is the shorter version of Application Programming Interface. In simple an API is like waiter that accept a request/order from you and what you are requested from get that and then delivers to you.
    i)GET: This is the mostly used data requesting method. You can request data from a specified resources. Get carries the request parameter in the URL that's why this method is not much secure
    ii) POST: POST method used to send data to the server. Post carries request parameter in the message-body that's why post method is mostly secured than get.

Discussion (0)