Answer:
- Don’t use any of the JavaScript reserved keyword as variable name. For example, break or boolean variable names are not valid.
- JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character. For example, 123name is an invalid variable name but _123name or name123 is a valid one.
- JavaScript variable names are case sensitive. For example, Test and test are two different variables.
Q39. What’s the way to resolve the delay in project time?
Answer: Attributes- provide more details on an element like id, type, value etc.
Property- is the value assigned to the property like type=”text”, value=’Name’ etc.
Q40.What is a Typed language?
Answer: Typed Language is a type of language in which the values are associated with values and not with variables. It is of two types:
Dynamically: the variable can hold multiple types; like in JS a variable can take number, chars.
Statically: the variable can hold only one type, like in Java a variable declared of string can take only set of characters and nothing else.
Q41. Name some of the JavaScript Framework?
Answer: A JavaScript framework is an application framework written in JavaScript. It differs from a JavaScript library in its control flow. There are many JavaScript Frameworks available but some of the most commonly used frameworks are:
Q42. What is the difference between innerHTML & innerText?
Answer: InnerHTML – It will process an HTML tag if found in a string
InnerText – It will not process an HTML tag if found in a string
Q43. What are Exports & Imports?
Answer: Imports and exports help us to write modular JavaScript code. Using Imports and exports we can split our code into multiple files
Q44.What are escape characters in JavaScript?
Answer: Escape characters enable to write special characters without breaking the application. It is used when working with special characters like single quotes, double quotes, apostrophes and ampersands. Place backslash before the characters to make it display.
Q45. What is a prompt box?
Answer: A prompt is a type of box. It allows the user to enter their input, provide a text box, number, and text provided by label and box.
Q46. What are all the loops available in JavaScript?
Answer: The loops available in JavaScript are,
For loop statement: It is the same as for loops of Java and C which continues until a specified condition evaluates to false.
Ex:-for(int i=0; i<=3; i++)
While loop: It executes its statement until a specified condition evaluates to true.
Ex: - while(Condition)
Statement
do-while loops: continues until a specified condition is false.
Ex:-do
statement
while(Condition)
Q47.What is the use of the delete operator?
Answer: The Delete keyword is used for deleting purposes which is used to delete the property as well as its value also.
Example:-
var student= {age:20, batch:”ABC”};
delete student.age;
Q48. Name some built-in methods in JavaScript?
Answer:
- anchor() – Creates an HTML anchor to be used as a hypertext target
- ceil() – returns the smallest integer that is greater than or equal to the given number
- concat() – Combines two strings and returns the newer string
- constructor() – Returns the function that created the corresponding instance of the object
- Date() – Returns the present date and time
Q49. How can you read a cookie in JavaScript?
Answer: By using our JavaScript concept we can read a cookie given below:-
var x = document.cookie;
Q50. How to handle exceptions in JavaScript?
Answer: The exception is the abnormal termination of a program is called an exception.It are caused by our program, not by our lack of system resources. An alternative way to continue the rest of the program is typically called exception handling.We can handle the exception with Try-catch and finally keyword, or we can say that Try-Catch block finally is used to handle exceptions in JavaScript.
Try-catch block is used to handle the exception, and the ‘finally’ block is bound to call either their call of try-catch block or not, but finally, the block is bound to call.
Syntax:
Try{
//Code
}
Q51.What do you mean by variable typing in JavaScript?
Answer: Variable typing is used for assigning a number to a variable and after that assigning string to that same variable.
i= 8; The steps using which you can get more clarifications are given below through an Example:-
i= 8;
i=”john”;
Q52. What are the different types of errors are available in JavaScript?
Answer: The three types of errors are:
Load time Errors: come up when we load a web page with inappropriate syntax Errors are otherwise known as Load time Errors. Load time Errors are generated dynamically.
Run time Errors: are generated due to misuse of command inside an HTML language are known as Run time errors.
Logical Errors: occur due to the formation or writing off bad logic inside the program, which logic has different operations known as Logical errors.
Q53. What do you mean by unshift method in JavaScript ?
Answer: Unshift method work is similar to the push method but pushes method to append the elements and pretend the elements. It works beginning of the array. This method is used to pretend one or more than one element at the beginning of an array.
Q54. How to print Statements in JavaScript?
Answer: By using Console.log () function in JavaScript, we can print any variables defined before int, and it is also used to print any message that needs to get displayed to the user. The Syntax for defining or showing elements to the user is:-console. log(A);
Q55. What is the difference between JavaScript and Jscript?
Answer: The difference between these two scripts is said to be no different. Both are pretty similar, but the only difference is JavaScript ids developed by Netscape and Jscript is developed by Microsoft.
Q56. Name the keyword which is used to print the text on the screen?
Answer: Write the text on the screen through the document.
“document.write (“Welcome”);”
After that, it will write welcome on the screen.
Q57. Explain WeakMap in JavaScript?
Answer: The map is usually used to store key-value pairs. It can be both primitive and non-primitive types. If the keys and values must be always an object in weakmap. If there are no object references then the garbage collector collects the object.
Q58. What are generator functions?
Answer:
Generator function helps to generate new values using the keyword yield.The major work of the yield keyword is to pause the execution of the function in the middle send the details to the function call and resume at the state where the yield was before the interruption.
Syntax:
function* gen()
{
yield 1;
yield 2;
…}
Q59. What is the use of promises in JavaScript?
Answer:
Any asynchronous operations that occur in JavaScript is handled by promises. There are four stages of promises in JavaScript:
- Pending – It acts to be a waiting list neither fulfilled nor rejected. It is the initial state.
- Fulfilled – Any Asynchronous operation is completed to ensure that the promise has been fulfilled.
- Rejected – Asynchronous reason that’s incomplete ensures that the promise has been rejected.
- Settled – This is a neutral state where the promise is neither rejected nor fulfilled.
Q60. What is the role of deferred scripts in JavaScript?
Answer: The parsing of HTML code during page loading is by default paused until the script has not halted executing. The webpage is delayed if the server is slow or the script is chiefly heavy.
When using the Deferred, scripts would delay execution of the script until the HTML parser is operating. It decreases the web pages’ loading time and they get showcased faster.
Q61. What are the different functional components in JavaScript?
Answer: Functional components are important topics covered in a javascript Course.
Two types of functional components in JavaScript are –First-class functions and nested functions.
- First-class functions: These functions in JavaScript are used as first-class objects. Usually, this means that such functions can be passed in form of arguments to other functions. Moreover, they are returned as values from other functions or assigned to variables, or they can be saved in data structures.
- Nested functions: Those functions that are defined within other functions are termed Nested functions. Whenever the main function is invoked, nested functions are called.
Q62. What is ECMAScript?
Answer: ECMAScript is a scripting language standardized by ECMA International in ECMA-262. Languages like ActionScript, JavaScript, and many more scripting languages are used ECMAScript, among these JavaScript is a well know client-side scripting language and an implementation of ECMAScript, since the standard was published. The latest version is ECMAScript6.
Q63. What is the Self-Executing Function?
Answer: The self-executing function will execute right after it has been defined. The advantage of using it is, it will execute the code without declaring any global. Mostly it will be used to attach event listeners to DOM elements and another initialization work.
Q64. What are classes in JavaScript?
Answer: The templates of JavaScript objects are Classes in JavaScript
Every class in JavaScript must have a constructor with it.
Syntax:
class ClassName
{constructor() { … }}
Q65. Explain WeakSet?
Answer:
Set is a collection of unique and ordered components in JavaScript. Weakset like Set, is a collection of unique and ordered elements, but there are certainly major differences: It only holds objects and no other types. A weakly referred item is one that is contained within the weakset. This means that if an item within the weakset lacks a reference, it will be trash collected. Unlike Set, only it has three methods add( ) , delete ( ) and has ( ).
Answer: By using JavaScript, we can create, read, and delete (crud operations) cookies with the “document. cookie” property.
To create a cookie JavaScript:
document.cookie = “username=John Doe”;
You can also add an expiry date for a cookie, but, by default, the expiry date of a cookie is when you close your respective browser, the cookie gets deleted or expired.