Javascript Deck 1 Flashcards

1
Q

What is JavaScript?

A

JavaScript is a lightweight, cross-platform, single-threaded, and interpreted compiled programming language. It is also known as the scripting language for webpages. It is well-known for the development of web pages, and many non-browser environments also use it.

Moreover, these frameworks enable developers to write code once and deploy it across various platforms. Hence, saving time and resources.
A single-threaded language is one that can execute only one task at a time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the differences between Java and JavaScript?

A

JavaScript is a client-side scripting language and Java is object Oriented Programming language. Both of them are totally different from each other.

JavaScript: It is a light-weighted programming language (“scripting language”) for developing interactive web pages. It can insert dynamic text into the HTML elements. JavaScript is also known as the browser’s language.
Java: Java is one of the most popular programming languages. It is an object-oriented programming language and has a virtual machine platform that allows you to create compiled programs that run on nearly every platform. Java promised, “Write Once, Run Anywhere”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are JavaScript Data Types?

A

There are three major Data types in JavaScript.

Primitive
Numbers
Strings
Boolean
Symbol

Trivial
Undefined
Null

Composite
Objects
Functions
Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which symbol is used for comments in JavaScript?

A

Comments prevent the execution of statements. Comments are ignored while the compiler executes the code. There are two type of symbols to represent comments in JavaScript:

Double slash: It is known as a single-line comment.
// Single line comment
Slash with Asterisk: It is known as a multi-line comment.

/*
Multi-line comments

*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What would be the result of 3+2+”7″?

A

Here, 3 and 2 behave like an integer, and “7” behaves like a string. So 3 plus 2 will be 5. Then the output will be 5+”7″ = 57.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the use of the isNaN function?

A

The number isNan function determines whether the passed value is NaN (Not a number) and is of the type “Number”. In JavaScript, the value NaN is considered a type of number. It returns true if the argument is not a number, else it returns false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which is faster in JavaScript and ASP script?

A

JavaScript is faster compared to ASP Script. JavaScript is a client-side scripting language and does not depend on the server to execute. The ASP script is a server-side scripting language always dependable on the server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is negative infinity?

A

The negative infinity is a constant value represents the lowest available value. It means that no other number is lesser than this value. It can be generate using a self-made function or by an arithmetic operation. JavaScript shows the NEGATIVE_INFINITY value as -Infinity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is it possible to break JavaScript Code into several lines?

A

Yes, it is possible to break the JavaScript code into several lines in a string statement. It can be broken by using the backslash ‘\’.
For example:

document.write(“A Online Computer Science Portal\ for Geeks”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are undeclared and undefined variables?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write a JavaScript code for adding new elements dynamically.

A
<script>
function create() { 
            let geeks = document.createElement('geeks'); 
            geeks.textContent = "Geeksforgeeks"; 
            geeks.setAttribute('class', 'note'); 
            document.body.appendChild(geeks); 
        }
</script>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

. What are global variables? How are these variables declared, and what are the problems associated with them?

A

In contrast, global variables are the variables that define outside of functions. These variables have a global scope, so they can be used by any function without passing them to the function as parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do you mean by NULL in JavaScript?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to delete property-specific values?

A

The delete keyword deletes the whole property and all the values at once like

let gfg={Course: “DSA”, Duration:30};
delete gfg.Course;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the ‘this’ keyword in JavaScript?

A

Functions in JavaScript are essential objects. Like objects, it can be assign to variables, pass to other functions, and return from functions. And much like objects, they have their own properties. ‘this’ stores the current execution context of the JavaScript program. Thus, when it use inside a function, the value of ‘this’ will change depending on how the function is defined, how it is invoked, and the default execution context.

16
Q

Explain the working of timers in JavaScript. Also elucidate the drawbacks of using the timer, if any.

A

The timer executes some specific code at a specific time or any small amount of code in repetition to do that you need to use the functions setTimout, setInterval, and clearInterval. If the JavaScript code sets the timer to 2 minutes and when the times are up then the page displays an alert message “times up”. The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

16
Q

What is a prompt box?

A

The prompt box is a dialog box with an optional message prompting the user to input some text. It is often used if the user wants to input a value before entering a page. It returns a string containing the text entered by the user, or null.

17
Q

What is the difference between ViewState and SessionState?

A

ViewState: It is specific to a single page in a session.
SessionState: It is user specific that can access all the data on the web pages.

18
Q

How to submit a form using JavaScript?

A

You can use document.form[0].submit() method to submit the form in JavaScript.

19
Q

Does JavaScript support automatic type conversion?

A

Yes, JavaScript supports automatic type conversion.

20
Q

what is JavaScript support automatic type conversion?

A

Type conversion (or typecasting) means transfer of data from one data type to another. Implicit conversion happens when the compiler (for compiled languages) or runtime (for script languages like JavaScript) automatically converts data types.

21
Q

Program to find longest word in a given sentence ?

A

Split the sentence into individual words, then iterate through each word to find and return the one with the greatest length.

22
Q

How to check whether a string is a palindrome or not?

A

A string is a palindrome if it reads the same forwards and backwards. To check, reverse the string and compare it to the original. If they are identical, the string is a palindrome.

`

23
Q

Write a program to remove duplicates from an array?

A

To remove duplicates, you can use a data structure that automatically handles uniqueness, like a Set. Convert the array into a Set, which removes any duplicate values, and then convert it back to an array.

24
Q

Program to find the reverse of a string without using built-in methods?

A

To reverse a string manually, iterate through the string from the end to the beginning and build a new string by appending each character.

25
Q

Find the max count of consecutive 1’s in an array?

A

Iterate through the array and keep a count of consecutive 1’s. Track the maximum count encountered as you iterate through the array.

26
Q

Find the factorial of a given number?

A

The factorial of a number is the product of all positive integers up to that number. You can calculate it using either a loop or recursion, multiplying the number by the factorial of the previous number.

27
Q

How many package.json and package-lock.json files does a React project have ? And what do they do

A

Number of Files:
A React project typically has one package.json file and one package-lock.json file at the root level of the project.

package.json File:

This file serves as the main configuration file for the project. It lists the project’s dependencies, scripts, and metadata (like the project name, version, and author). It helps manage and install the required packages and tools that the project depends on.
package-lock.json File:

This file is automatically generated when you run npm install. It locks the versions of the dependencies listed in package.json, ensuring that the project installs the exact same versions of dependencies across different environments. This file is crucial for maintaining consistency and avoiding unexpected bugs due to version changes.

28
Q

What are transitive dependencies?

A

Transitive dependencies are the indirect dependencies of a project. They are packages that your direct dependencies rely on. When you install a package in your project, that package might depend on other packages to work properly. These secondary dependencies are known as transitive dependencies.
Example:

Suppose your project depends on Package A, and Package A itself depends on Package B to function. Here, Package B is a transitive dependency of your project. Even though you didn’t directly install Package B, it is still included in your project’s dependency tree because Package A needs it.

Key Points:

Transitive dependencies are automatically installed when you install a package that requires them.
Managing transitive dependencies is important because updates or changes to them can affect your project, even if your direct dependencies haven’t changed.
Tools like npm and yarn manage these transitive dependencies for you and ensure that the correct versions are installed according to your package-lock.json or yarn.lock file.

29
Q
A