JS All Flashcards

1
Q

What is JavaScript?

A

JavaScript is a scripting language. Different from Java. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.

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

List some features of JavaScript

A

Interpreted programming language
Good for the applications which are network-centric
Complementary to Java
Complementary to HTML
Open source
Cross-platform

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

Who developed JavaScript

A

Developed by Brendan Eich, 1995 Mocha - Live Script - Java Script

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

Some of the advantages of JavaScript.

A

Server interaction is less
Feedback to the visitors is immediate
Interactivity is high
Interfaces are richer

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

Some of the disadvantages of JavaScript.

A

No support for multithreading
No support for multiprocessing
Reading and writing of files is not allowed
No support for networking applications.

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

Define a named function in JavaScript.

A

The function which has named at the time of definition is called a named function.
~~~
function msg()
{
document.writeln(“Named Function”);
}
msg();
~~~

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

Name the types of functions

A

The types of function are:

Named - These type of functions contains name at the time of definition.
~~~
function display()
{
document.writeln(“Named Function”);
}
display();
Anonymous - These type of functions doesn’t contain any name. They are declared dynamically at runtime.
var display=function()
{
document.writeln(“Anonymous Function”);
}
display();
~~~

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

Define anonymous function

A

It is a function that has no name. These functions are declared dynamically at runtime using the function operator instead of the function declaration. The function operator is more flexible than a function declaration. It can be easily used in the place of an expression.
~~~
var display=function()
{
alert(“Anonymous Function is invoked”);
}
display();
~~~

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

Can an anonymous function be assigned to a variable?

A

Yes, you can assign an anonymous function to a variable.

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

10) In JavaScript what is an argument object?

A

The variables of JavaScript represent the arguments that are passed to a function.

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

Closure.

A

In JavaScript, we need closures when a variable which is defined outside the scope in reference is accessed from some inner scope.
~~~
var num = 10;
function sum()
{
document.writeln(num+num);
}
sum();
~~~

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

If we want to return the character from a specific index which method is used?

A

charAt() method is used to find out a char value present at the specified index. The index number starts from 0 and goes to n-1, where n is the length of the string. The index value can’t be a negative, greater than or equal to the length of the string. For example:
~~~
var str=”Javatpoint”;
document.writeln(str.charAt(4));
~~~

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

Difference between JavaScript and JScript?

A

JScript is the same as JavaScript, but Microsoft provides it.

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

hello world example of JavaScript?

A

You need to place it inside the body tag of HTML.
~~~

  
document.write("JavaScript Hello World!");

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

What are the key in Java?

A

Java is a complete and strongly typed programming language used for backend coding. In Java, variables must be declared first to use in the program, and the type of a variable is checked at compile-time.
Java is an object-oriented programming (OOPS) language or structured programming languages such as C, C++, or .Net.
Java creates applications that can run in any virtual machine (JVM) or browser.
The Java code needs to be compiled.
Java Objects are class-based. You can’t make any program in Java without creating a class.
Java is a Complete and Standalone language that can be used in backend coding.
Java programs consume more memory.
The file extension of the Java program is written as “.Java” and it translates source code into bytecodes which are then executed by JVM (Java Virtual Machine).
Java supports multithreading.
Java uses a thread-based approach to concurrency.

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

What are the key in Java Script?

A

JS is a weakly typed, lightweight programming language and has more relaxed syntax and rules.
JS is a client-side scripting language, and it doesn’t fully support the OOPS concept. It used to make web pages interactive .
JS code can run only in the browser, but it can now run on the server via Node.js.
The JS code doesn’t require to be complied.
JS Objects are prototype-based.
JS is assigned within a web page and integrates with its HTML content.
JS code is used in HTML web pages and requires less memory.
The JS file extension is written as “.js” and it is interpreted but not compiled. Every browser has a JS interpreter to execute the JS code.
JS doesn’t support multithreading.
JS uses an event-based approach to concurrency.

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

How to use external JavaScript file?

A

js file name is message.js, place the following script tag inside the head tag.
~~~



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

Is JavaScript case sensitive language?

A

Yes, JavaScript is a case sensitive language.
~~~
Var msg = “JavaScript is a case-sensitive language”; //Here, var should be used to declare a variable
function display()
{
document.writeln(msg); // It will not display the result.
}
display();
~~~

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

What is BOM?

A

BOM stands for Browser Object Model. It provides interaction with the browser. The default object of a browser is a window. So, you can call all the functions of the window by specifying the window or directly. The window object provides various properties like document, history, screen, navigator, location, innerHeight, innerWidth,

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

What is DOM? What is the use of document object?

A

DOM stands for Document Object Model. A document object represents the HTML document. It can be used to access and change the content of HTML.

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

What is the use of window object?

A

The window object is created automatically by the browser that represents a window of a browser. It is not an object of JavaScript. It is a browser object.

The window object is used to display the popup dialog box.

Method Description
alert() displays the alert box containing the message with ok button.
confirm() displays the confirm dialog box containing the message with ok and cancel button.
prompt() displays a dialog box to get input from the user.
open() opens the new window.
close() closes the current window.
setTimeout() performs the action after specified time like calling function, evaluating expressions.

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

What is the use of history object?

A

The history object of a browser can be used to switch to history pages such as back and forward from the current page or another page. There are three methods of history object.

history.back() - It loads the previous page.
history.forward() - It loads the next page.
history.go(number) - The number may be positive for forward, negative for backward. It loads the given page number.

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

How to write a comment in JavaScript?

A

There are two types of comments in JavaScript.

Single Line Comment: It is represented by // (double forward slash)
Multi-Line Comment: Slash represents it with asterisk symbol as /* write comment here */

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

How to create a function in JavaScript?

A

Create a function in JavaScript, follow the following syntax.
~~~
function function_name(){
//function body
}
~~~

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

What are the different data types present in JavaScript?

A

There are two types of data types in JavaScript:

Primitive data types
Non- Primitive data types

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

Primitive data types String

A

String: The string data type represents a sequence of characters. It is written within quotes and can be represented using a single or a double quote.
~~~
var str1 = “Hello JavaTpoint”; //using double quotes
var str2 = ‘Hello Javatpoint’; //using single quotes
~~~

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

Primitive data types Number

A

Number: The number data type is used to represent numeric values and can be written with or without decimals.
~~~
var x = 5; //without decimal
var y = 5.0; //with decimal
~~~

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

Primitive data types Boolean

A

Boolean: The Boolean data type is used to represent a Boolean value, either false or true. This data type used for conditional testing.

var x = 5;  
var y =  6;  
var z =  5;  
(x == y) // returns false  
(x == z) //returns true  
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Primitive data types BigInt

A

BigInt: The BigInt data type is used to store numbers beyond the Number data type limitation. This data type can store large integers and is represented by adding “n” to an integer literal.
~~~
var bigInteger = 123456789012345678901234567890;
// This is an example of bigInteger.
~~~

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

Primitive data types Undefined

A

Undefined: The Undefined data type is used when a variable is declared but not assigned. The value of this data type is undefined, and its type is also undefined.
~~~
var x; // value of x is undefined
var y = undefined; // You can also set the value of a variable as undefined.
~~~

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

Primitive data types Null

A

Null: The Null data type is used to represent a non-existent, null, or a invalid value i.e. no value at all .

var  x = null;  
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Primitive data types Symbol

A

Symbol: Used to store an anonymous and unique value.
~~~
var symbol1 = Symbol(‘symbol’);
~~~

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

What is typeof?

A

typeof: The typeof operator is used to determine what type of data a variable or operand contains. It can be used with or without parentheses (typeof(x) or typeof x). This is mainly used in situations when you need to process the values of different types.
```typeof 10; // Returns: “number”
typeof 10.0; // Returns: “number”
typeof 2.5e-4; // Returns: “number”
typeof Infinity; // Returns: “number”
typeof NaN; // Returns: “number”. Despite being “Not-A-Number”
// Strings
typeof ‘’; // Returns: “string”
typeof ‘Welcome to JavaTpoint’; // Returns: “string”
typeof ‘12’; // Returns: “string”. Number within quotes is typeof string
// Booleans
typeof true; // Returns: “boolean”
typeof false; // Returns: “boolean”
// Undefined
typeof undefined; // Returns: “undefined”
typeof undeclaredVariable; // Returns: “undefined”
// Null
typeof Null; // Returns: “object”
// Objects
typeof {name: “John”, age: 18}; // Returns: “object”
// Arrays
typeof [1, 2, 3]; // Returns: “object”
// Functions
typeof function(){}; // Returns: “function”
~~~

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

Non-Primitive data types Object

A

Object: The Object is a non-primitive data type, used to store collections of data. An object contains properties, defined as a key-value pair. A property key (name) is always a string, but the value can be any data type, such as strings, numbers, Booleans, or complex data types like arrays, functions, and other objects.
~~~
// Collection of data in key-value pairs
var obj1 = {
x: 123,
y: “Welcome to JavaTpoint”,
z: function(){
return this.x;
}
}
~~~

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

Non-Primitive data types Array

A

Array: The Array data type is used to represent a group of similar values. Every value in an array has a numeric position, called its index, and it may contain data of any data type-numbers, strings, Booleans, functions, objects, and even other arrays. The array index starts from 0 so that the first array element is arr[0], not arr[1].
~~~
var colors = [“Red”, “Yellow”, “Green”, “Orange”];
var cities = [“Noida”, “Delhi”, “Ghaziabad”];
alert(colors[2]); // Output: Green
alert(cities[1]); // Output: Delhi
~~~

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

What is the difference between == and ===?

A

The == operator checks equality only whereas === checks equality, and data type, i.e., a value must be of the same type.

37
Q

How to write HTML code dynamically using JavaScript?

A

The innerHTML property is used to write the HTML code using JavaScript dynamically.
~~~
document.getElementById(‘mylocation’).innerHTML=”<h2>This is heading using JavaScript</h2>”;
~~~

38
Q

How to write normal text code using JavaScript dynamically?

A

The innerText property is used to write the simple text using JavaScript dynamically.
~~~
document.getElementById(‘mylocation’).innerText=”This is text using JavaScript”;
~~~

39
Q

How to create objects in JavaScript?

A

3 ways to create an object in JS

By object literal
By creating an instance of Object
By Object Constructor
- object using object literal.
~~~
emp={
id:102,name:”Rahul Kumar”,
salary:50000
}
~~~

40
Q

How to create an array in JavaScript?

A

3 ways to create an array in JavaScript.

By array literal
By creating an instance of Array
By using an Array constructor
- create an array using object literal.
~~~
var emp=[“Shyam”,”Vimal”,”Ratan”];
~~~

41
Q

What does the isNaN() function?

A

The isNan() function returns true if the variable value is not a number.
~~~
function number(num) {
if (isNaN(num)) {
return “Not a Number”;
}
return “Number”;
}
console.log(number(‘1000F’));
// expected output: “Not a Number”

console.log(number(‘1000’));
// expected output: “Number”
~~~

42
Q

What is the output of 10+20+”30” in JavaScript?

A

3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).
~~~
function display()
{
document.writeln(10+20+”30”);
}
display();
~~~

43
Q

What is the output of “10”+20+30 in JavaScript?

A

102030 because after a string all the + will be treated as string concatenation operator (not binary +).
~~~
function display()
{
document.writeln(“10”+20+30);
}
display();
~~~

44
Q

Difference between Client side JS and Server side JS?

A

Client-side JavaScript comprises the basic language and predefined objects which are relevant to running JavaScript in a browser. The client-side JavaScript is embedded directly by in the HTML pages. The browser interprets this script at runtime.

Server-side JavaScript also resembles client-side JavaScript. It has a relevant JavaScript which is to run in a server. The server-side JavaScript are deployed only after compilation.

45
Q

In which location cookies are stored on the hard disk?

A

The storage of cookies on the hard disk depends on the OS and the browser.

The Netscape Navigator on Windows uses a cookies.txt file that contains all the cookies. The path is
~~~
c:\Program Files\Netscape\Users\username\cookies.txt
~~~
The Internet Explorer stores the cookies on a fileusername@website.txt.The path is:
```c:\Windows\Cookies\username@Website.txt.
~~~

46
Q

What’s the difference between event.preventDefault() and event.stopPropagation() methods in JS?

A

In JS, the event.preventDefault() method is used to prevent the default behavior of an element.
-If you use it in a form element, it prevents it from submitting. If used in an anchor element, it prevents it from navigating. If used in a contextmenu, it prevents it from showing or displaying.
- event.stopPropagation() method is used to stop the propagation of an event or stop the event from occurring in the bubbling or capturing phase.

47
Q

What is the real name of JS?

A

The original name wasMocha, a name chosen by Marc Andreessen, founder of Netscape.
September of 1995, changed to LiveScript.
December 1995, after receiving a trademark license from Sun, the name JS

48
Q

How can you check if the event.preventDefault() method was used in an element?

A

When we use the event.defaultPrevent() method in the event object returns a Boolean indicating that the event.preventDefault() was called in a particular element.

49
Q

What is the difference between undefined value and null value?

A

-Undefined value:A value that is not defined and has no keyword is known as undefined value.
~~~
int number;//Here, a number has an undefined value.
~~~
-Null value:A value that is explicitly specified by the keyword “null” is known as a null value.
~~~
String str=null;//Here, str has a null value.
~~~

50
Q

How to set the cursor to wait in JS?

A

The cursor can be set to wait in JS by using the property “cursor”.
~~~

  
window.document.body.style.cursor = "wait";

~~~
51
Q

What is this [[[]]]?

A

This is a three-dimensional array.
~~~
var myArray = [[[]]];```

52
Q

What is negative infinity?

A

Negative Infinity is a number in JavaScript which can be derived by dividing the negative number by zero.
~~~
var num=-5;
function display()
{
document.writeln(num/0);
}
display();
//expected output: -Infinity
~~~

53
Q

Are Java and JS same?

A

No, Java and JS are the two different languages.
-Java is a robust, secured and object-oriented programming language whereas -JS is a client-side scripting language with some limitations.

54
Q

What is the difference between View state and Session state?

A

“View state” is specific to a page in a session whereas “Session state” is specific to a user or browser that can be accessed across all pages in the web application.

55
Q

What are the pop-up boxes available in JavaScript?

A

Alert Box
Confirm Box
Prompt Box

56
Q

alert() in JavaScript

A
<script type="text/javascript">  
function msg(){  
 alert("Hello Alert Box");  
}  
</script>  <input type="button" value="click" onclick="msg()"/>  
57
Q

confirm() in JavaScript

A
<script type="text/javascript">  
function msg(){  
var v= confirm("Are u sure?");  
if(v==true){  
alert("ok");  
}  
else{  
alert("cancel");  
}  
  
}  
</script>  
  
<input type="button" value="delete record" onclick="msg()"/>  
58
Q

prompt() in JavaScript

A
<script type="text/javascript">  
function msg(){  
var v= prompt("Who are you?");  
alert("I am "+v);  
  
}  
</script>  
  
<input type="button" value="click" onclick="msg()"/>  
59
Q

How can we detect OS of the client machine using JavaScript?

A

The navigator.appVersion string can be used to detect the operating system on the client machine.

60
Q

How to submit a form using JavaScript by clicking a link?

A
<form name="myform" action="index.php">  
Search: <input type='text' name='query' />  
<a href="javascript: submitform()">Search</a>  
</form>  
<script type="text/javascript">  
function submitform()  
{  
  document.myform.submit();  
}  
</script>  
61
Q

Is JavaScript faster than ASP script?

A

Yes, because it doesn’t require web server’s support for execution.

62
Q

How to change the background color of HTML document using JavaScript?

A
<script type="text/javascript">  
document.body.bgColor="pink";  
</script> 
63
Q

How to handle exceptions in JavaScript?

A

By the help of try/catch block, we can handle exceptions in JavaScript. JavaScript supports try, catch, finally and throw keywords for exception handling.

64
Q

How to validate a form in JavaScript?

A
<script>  
function validateform(){  
var name=document.myform.name.value;  
var password=document.myform.password.value;  
  if (name==null || name==""){  
  alert("Name can't be blank");  
  return false;  
}else if(password.length<6){  
  alert("Password must be at least 6 characters long.");  
  return false;  
  }  
}  
</script>  
<body>  
<form name="myform" method="post" action="abc.jsp" onsubmit="return validateform()" >  
Name: <input type="text" name="name"><br/>  
Password: <input type="password" name="password"><br/>  
<input type="submit" value="register">  
</form>
65
Q

How to validate email in JavaScript?

A
<script>  
function validateemail()  
{  
var x=document.myform.email.value;  
var atposition=x.indexOf("@");  
var dotposition=x.lastIndexOf(".");  
if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length){  
  alert("Please enter a valid e-mail address \n atpostion:"+atposition+"\n dotposition:"+dotposition);  
  return false;  
  }  
}  
</script>  
<body>  
<form name="myform"  method="post" action="#" onsubmit="return validateemail();">  
Email: <input type="text" name="email"><br/>  
  
<input type="submit" value="register">  
</form>  
66
Q

What is this keyword in JavaScript?

A

The this keyword is a reference variable that refers to the current object.
~~~
var address=
{
company:”Javatpoint”,
city:”Noida”,
state:”UP”,
fullAddress:function()
{
return this.company+” “+this.city+” “+this.state;
}
};
var fetch=address.fullAddress();
document.writeln(fetch);
~~~

67
Q

What is the requirement of debugging in JavaScript?

A

JavaScript didn’t show any error message in a browser.
The best practice to find out the error is to debug the code. whit web browsers like Google Chrome, Mozilla Firebox.

To perform debugging, we can use any of the following approaches:

Using console.log() method
Using debugger keyword

68
Q

What is the use of debugger keyword in JavaScript?

A

JavaScript debugger keyword sets the breakpoint through the code itself. The debugger stops the execution of the program at the position it is applied. Now, we can start the flow of execution manually. If an exception occurs, the execution will stop again on that particular line..
~~~
function display()
{
x = 10;
y = 15;
z = x + y;
debugger;
document.write(z);
document.write(a);
}
display();
~~~

69
Q

What is the role of a strict mode in JavaScript?

A

The JavaScript strict mode is used to generates silent errors. It provides “use strict”; expression to enable the strict mode. This expression can only be placed as the first statement in a script or a function.
~~~
“use strict”;
x=10;
console.log(x);
~~~

70
Q

What is the use of Math object in JavaScript?

A

The JavaScript math object provides several constants and methods to perform a mathematical operation. Unlike date object, it doesn’t have constructors.
~~~
function display()
{
document.writeln(Math.random());
}
display();
~~~

71
Q

What is the use of a Date object in JavaScript?

A

The JavaScript date object can be used to get a year, month and day. You can display a timer on the webpage by the help of JavaScript date object.
~~~
function display()
{
var date=new Date();
var day=date.getDate();
var month=date.getMonth()+1;
var year=date.getFullYear();
document.write(“<br></br>Date is: “+day+”/”+month+”/”+year);
}
display();
~~~

72
Q

What is the use of a Number object in JavaScript?

A

The JavaScript number object enables you to represent a numeric value. It may be integer or floating-point. JavaScript number object follows the IEEE standard to represent the floating-point numbers.
~~~
function display()
{
var x=102;//integer value
var y=102.7;//floating point value
var z=13e4;//exponent value, output: 130000
var n=new Number(16);//integer value by number object
document.write(x+” “+y+” “+z+” “+n);
}
display();
~~~

73
Q

What is the use of a Boolean object in JavaScript?

A

The JavaScript Boolean is an object that represents value in two states: true or false. You can create the JavaScript Boolean object by Boolean() constructor.
~~~
function display()
{
document.writeln(10<20);//true
document.writeln(10<5);//false
}
display();
~~~

74
Q

What is the use of a TypedArray object in JavaScript?

A

The JavaScript TypedArray object illustrates an array like a view of an underlying binary data buffer. There is any number of different global properties, whose values are TypedArray constructors for specific element types.
~~~
function display()
{
var arr1= [1,2,3,4,5,6,7,8,9,10];
arr1.copyWithin(2) ;
document.write(arr1);
}
display();
~~~

75
Q

What is the use of a Set object in JavaScript?

A

The JavaScript Set object is used to store the elements with unique values. The values can be of any type i.e. whether primitive values or object references.
~~~
function display()
{
var set = new Set();
set.add(“jQuery”);
set.add(“AngularJS”);
set.add(“Bootstrap”);
for (let elements of set) {
document.writeln(elements+”<br></br>”);
}
}
display();
~~~

76
Q

What is the use of a WeakSet object in JavaScript?

A

The JavaScript WeakSet object is the type of collection that allows us to store weakly held objects. Unlike Set, the WeakSet are the collections of objects only. It doesn’t contain the arbitrary values.
~~~
function display()
{
var ws = new WeakSet();
var obj1={};
var obj2={};
ws.add(obj1);
ws.add(obj2);
//Let’s check whether the WeakSet object contains the added object
document.writeln(ws.has(obj1)+”<br></br>”);
document.writeln(ws.has(obj2));
}
display()
~~~

77
Q

What is the use of a Map object in JavaScript?

A

The JavaScript Map object is used to map keys to values. It stores each element as key-value pair. It operates the elements such as search, update and delete on the basis of specified key.
~~~
function display()
{
var map=new Map();
map.set(1,”jQuery”);
map.set(2,”AngularJS”);
map.set(3,”Bootstrap”);
document.writeln(map.get(1)+”<br></br>”);
document.writeln(map.get(2)+”<br></br>”);
document.writeln(map.get(3));
}
display();
~~~

78
Q

What is the use of a WeakMap object in JavaScript?

A

The JavaScript WeakMap object is a type of collection which is almost similar to Map. It stores each element as a key-value pair where keys are weakly referenced. Here, the keys are objects and the values are arbitrary values.
~~~
function display()
{
var wm = new WeakMap();
var obj1 = {};
var obj2 = {};
var obj3= {};
wm.set(obj1, “jQuery”);
wm.set(obj2, “AngularJS”);
wm.set(obj3,”Bootstrap”);
document.writeln(wm.has(obj2));
}
display();
~~~

79
Q

What are the falsy values in JavaScript, and how can we check if a value is falsy?

A

Those values which become false while converting to Boolean are called falsy values.
~~~
const falsyValues = [’’, 0, null, undefined, NaN, false];
~~~

80
Q

What do you understand by hoisting in JavaScript?

A

Hoisting is the default behavior of JavaScript where all the variable and function declarations are moved on top. Hoisting is a process in which, irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.
~~~
hoistedVariable = 12;
console.log(hoistedVariable); // outputs 12 even when the variable is declared after it is initialized
var hoistedVariable;
~~~

hoistedFunction();  // Outputs " Welcome to JavaTpoint " even when the function is declared after calling  
function hoistedFunction(){   
  console.log(" Welcome to JavaTpoint ");  
}  
// Hoisting in a local scope   
function doSomething(){  
  x = 11;  
  console.log(x);  
  var x;  
}  
doSomething(); // Outputs 11 since the local variable "x" is hoisted inside the local s
81
Q

Which of the following statement is true?

a If onKeyDown returns false, the key-up event is canceled.
b If onKeyDown returns false, the key-press event is canceled.
c If onKeyPress returns false, the key-down event is canceled.
d If onKeyPress returns false, the key-up event is canceled.

A

B is the correct option.

82
Q

Which of the following statement shows the primary difference between JS and Java?

a There is no difference between JS and Java.
b Functions are considered as fields.
c Variables are specific.
d Functions are values, and there is no such distinction between methods and fields.

A

D is the correct option. We know that Java is an OOP language while JavaScript is an OOP scripting language. The most fundamental difference between JavaScript and Java is that the functions are values, and there is no such distinction between methods and fields.

83
Q

Which of the following syntax is valid for creating a RegExp object?

1.vartxt=newRegExp(pattern,attributes);
2.vartxt=/pattern/attributes;

a Only 1 syntax
b Only 2 syntax
c Both 1 and 2 syntax
dNone of the above

A

C: Both the statements are correct and can be used for creating a RegExp object.

84
Q

Which of the following statement specifies the meaning of Augmenting classes?

a Objects inherit prototype properties even in a dynamic state.
b Objects inherit prototype properties only in a dynamic state.
c Objects inherit prototype properties in the static state.
d An object doesn’t inherit prototype properties in the static state.

A

A: “Objects inherit prototype properties even in a dynamic state” is the correct answer.

85
Q

If para1 is the DOM object for a paragraph, which of the following would be the correct syntax to change the text within the paragraph?

a para1=”New Text”
b firstChild.nodeValue= “New
Text”;
c value=”New Text”;
d nodeValue=”New Text”;

A

C: “para1.value=”New Text”;” is the correct syntax to change the text within the paragraph.

86
Q

Which of the following statement is true in the case of the property of the JSON() method?

a A JSON() method can be invoked manually as object.JSON()
b A JSON() method is invoked automatically by the JSON.stringify() method
c A JSON() method is automatically invoked by the compiler.
d A JSON() method cannot be invoked in any form.

A

B is the correct option. The JSON() method is most commonly used to exchange data to/from a web server. When we send data to a web server, the data has to be a string. In this case, json.strigify() is used to convert a JavaScript object into a string.

87
Q

Which of the following statement is true if class B can extend another class A?

a A is the superclass, and B is the subclass.
b B is the superclass, and A is the subclass.
c Both A and B are the superclass.
d Both A and B are subclass.

A

A: “A is the superclass and B is the subclass” is the correct answer. A class is called a superclass if it can define a subclass. Subclasses are also called extensions of a superclass.

88
Q

Which of the following is the correct syntax of the eval() function?

a [objectName.]eval(numeric)
b [EvalName.]eval(string)
c [EvalName.]eval(numeric)
d [objectName.]eval(string)

A

D is the correct option. The eval() function is used to evaluate or execute an argument. If the argument is an expression, the eval() function evaluates the expression. If the argument is one or more JavaScript statements, the eval() function executes the statements.

89
Q

What would be the output of the following JS code?
~~~
const obj1 =
{
a: 10,
b: 15,
c: 18
};
const obj2 = Object.assign({c: 11, d: 12}, obj1);

console.log(obj2.c, obj2.d);
~~~

a 10, 12
b 11, 12
c Undefined
d Error

A

B: 11, 12 is the correct answer. The Object.assign() method is used to copy the properties and values of one object to another.