Java Script Interview Questions and Answers

Comments ยท 124 Views

JavaScript is the most powerful and versatile web programming language. It is used for making the websites interactive. JavaScript helps us add features like animations, interactive forms and dynamic content to web pages.

Q-1.What are the various data types that exist in JavaScript?

These are the different types of data that JavaScript supports:

    Boolean - For true and false values
    Null - For empty or unknown values
    Undefined - For variables that are only declared and not defined or initialized
    Number - For integer and floating-point numbers
    String - For characters and alphanumeric values
    Object - For collections or complex values
    Symbols - For unique identifiers for objects

Q-2. What are the scopes of a variable in JavaScript?

The scope of a variable implies where the variable has been declared or defined in a JavaScript program. There are two scopes of a variable:

Global Scope

Global variables, having global scope are available everywhere in a JavaScript code.

Local Scope

Local variables are accessible only within a function in which they are defined.

 

Q-3.Differences between var, let, and const ?

varletconst
The scope of a var variable is functional or global scope.The scope of a let variable is block scope.The scope of a const variable is block scope.
It can be updated and re-declared in the same scope.It can be updated but cannot be re-declared in the same scope.It can neither be updated or re-declared in any scope.
It can be declared without initialization.It can be declared without initialization.It cannot be declared without initialization.
It can be accessed without initialization as its default value is “undefined”.It cannot be accessed without initialization otherwise it will give ‘referenceError’.It cannot be accessed without initialization, as it cannot be declared without initialization.
These variables are hoisted.These variables are hoisted but stay in the temporal dead zone untill the initialization.These variables are hoisted but stays in the temporal dead zone until the initialization.

 

Q.4 What are undeclared and undefined variables?

Undefined: It occurs when a variable has been declared but has not been assigned any value. Undefined is not a keyword. 

Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using the var or const keyword. If we use ‘typeof’ operator to get the value of an undeclared variable, we will face the runtime error with the return value as “undefined”. The scope of the undeclared variables is always global. 

Q-5.What do you mean by NULL in JavaScript?

 The NULL value represents that no value or no object. It is known as empty value/object

 

Comments