You are on page 1of 5

1. What is JavaScript and its advantages?

JavaScript is a scripting language that enables you to create dynamically update


content, control multimedia, animate images, and pretty much everything else.
Advantages
• Saves time and bandwidth
• Compatible for all browsers
• Easily send HTTP requests.

2)What are the different types of data types in JavaScript?

• JavaScript has 8 Datatypes


1. String
2. Number
3. Bigint
4. Boolean
5. Undefined
6. Null
7. Symbol
8. Object
3) Explain Hoisting in JavaScript?
Hoisting is a term used to explain the behavior of variable declarations in code.
4) Difference between ‘==’ and ‘===’ operators?
- `==` checks for equality after converting types to match if needed.
- `===` checks for equality without converting types.
5) Difference between var and let?

• `var` is function-scoped and can be redeclared within the same scope


• `let` is block-scoped and cannot be redeclared within the same scope
6) Explain implicit Type Coercion in JavaScript?
It automatically converts values to the expected data type when operators are
applied.
7) What is Nan property in JavaScript?
`NaN` stands for "Not a Number."
It represents a value that is not a valid number.

`NaN` is returned when a mathematical operation cannot produce a meaningful


result.
8) Explain pass by value and pass by reference in JavaScript?

• Pass by value: Copies the actual value to the function parameter.


• Pass by reference: Passes a reference (memory address) to the function
parameter.
9) what is an immediately invoked function in javascript?
A function that is called immediately after it is defined.
10)Explain call(), apply() and bind() method?
• call(thisArg, arg1, arg2, ...): The call method calls a function with a given this value
and arguments provided individually.
• apply(thisArg, [argsArray]): The apply method calls a function with a given this value
and arguments provided as an array or array-like object.
• bind(thisArg, arg1, arg2, ...): The bind is used to create a new function with a specific
this context and pre-set arguments that can be called later.

11) What are object prototypes?


A mechanism for sharing and reusing properties and methods among objects
through inheritance.
12) What is memoization?
A Technique used to cache the results of expensive function calls and return the
cached result when the same inputs occur again, improving performance.
13) What is DOM?
DOM stands for Document Object Model,
which is a programming interface for web documents.
14) What are arrow functions?
=> (syntax)
A compact alternative to a traditional function expression, with some semantic
differences and deliberate limitations in usage.
15) Difference between java and JavaScript?

• Java is a statically typed, object-oriented programming language for


general-purpose development.
• JavaScript is a dynamically typed, prototype-based scripting language
primarily used for web development.
16) Write a JavaScript code for adding new elements dynamically?
To add new elements dynamically to a webpage using JavaScript, you can use the
createElement method to create a new element, appendChild method to append it to an
existing element, and set its properties and attributes as needed.

// Create a new paragraph element

const newParagraph = document.createElement('p');

// Set the text content of the paragraph

newParagraph.textContent = 'This is a new paragraph added dynamically.';

// Append the new paragraph to the body of the document

document.body.appendChild(newParagraph);
17) What are global variables, how do you declare and problems associated with
global variables?
Global variables in JavaScript are variables that are declared outside of any
function.
var globalVariable = 'I am a global variable';
Problems

• Name Collisions
• Difficulty in Tracking
• Code Readability
18)What is prompt box?
The prompt box in JavaScript is a built-in function that displays a dialog box with a
message, an input field for the user to enter text, and buttons for the user to click
(typically "OK" and "Cancel").
The prompt box is often used to get user input in the form of a string.
19) What is the difference between view state and session state?

• View State maintains the state of a single page across postbacks


• Session State maintains the state of a user's session across multiple
requests.
20) Explain how to read and write a file by using java script?

• Reading a file: Use `fs.readFile` method to read a file asynchronously,


providing the file path and encoding as arguments.
• Writing to a file: Use `fs.writeFile` method to write to a file asynchronously,
providing the file path, content, and a callback function as arguments.
JavaScript alone cannot directly read or write files on the user's system for security
reasons. However, in a Node.js environment (server-side JavaScript), you can read and
write files using the built-in fs (file system) module.

You might also like