![](https://www.freecodecamp.org/news/content/images/2022/01/28.png)
Question-1:
Discuss the scope of var, let, and const
var: The var is the oldest keyword to declare a variable in JavaScript. The var keyword was historically used for variable declaration.
Scope : Variables declared with var are function-scoped, which means they are accessible within the function in which they are
declared, regardless of where they are declared within that function They are hoisted to the top of their containing function or global scope. This means that the variable declaration is moved to the top during the compilation phase, but the assignment remains where it is.
The variable declared with var outside of any function are attached to the global object. This can potentially lead to global namespace pollution and conflicts with other scripts.
let: The let keyword is an improved version of the var keyword.
Scope : Variables declared with let are block-scoped, meaning they are limited to the block like loops, conditional statements, and functions. let is hoisted, but is not initialized until the actual declaration is reached. Also we can't redeclare a let variable in the same block scope.
const: We use the const keyword in JavaScript to declare variables whose value can be initialized only at the time of
declaration.
Scope : const variables are block-scoped. It is also hoisted, but is not initialized until the actual declaration is reached. Once a value is assigned to a const variable, it cannot be changed. It's a constant. Also, we cannot re-declare a const variable within the same block scope.
Question-2:
Tell us the use cases of null and undefined
The value undefined means a variable has been declared but has not yet been assigned a value. undefined is a
type by itself (undefined). Unassigned variables are initialized by JavaScript with a default value of undefined.
On the otherhand, null is an object. It can be assigned to a variable as a representation of no value.
JavaScript never sets a value to null. That must be done programmatically.
UseCase of null and undefined
When a variable is declared but not assigned a value, it is automatically initialized with undefined. The
functions usually do not return undefined. Simply which is not existed is undefined. On the otherhand, we can
set a variable or object property to null to clear its previous value. We also used null in conditional
statement to check if a value has been intentionally set to noting.
![](https://www.syncfusion.com/blogs/wp-content/uploads/2022/11/Null-vs.-Undefined-in-JavaScript-1.png)
![](https://images.velog.io/images/vsnm25/post/0692367a-3209-4460-bd84-28f33f6231f4/restAPI.png)
Question-3:
What do you mean by REST API?
REST API is a simple and flexible method of accessing web services that does not require any processing. It is an API that adheres to the REST, or representational state transfer, architectural style's design principles. REST technology is often favoured over the more sophisticated Simple Object Access Protocol (SOAP) technology because it consumes less bandwidth, is simpler, and more adaptable to internet use. It is used to retrieve or provide information from a web service. All REST API connection involves only HTTP requests.