1. What is JavaScript? (This is a basic question, and for many programmers it is a bonus question!)

JavaScript is a client-side and server-side scripting language that can be inserted into HTML pages and is currently the most popular Web development language. JavaScript is also an object-oriented programming language.

Similar basic questions include: What are the types of JavaScript? Who invented JavaScript? .

2. List the differences between Java and JavaScript.

Java is a very complete and mature programming language.

JavaScript, by contrast, is a programming language that can be imported into HTML pages. The two languages are not completely interdependent, but are designed for different purposes. Java is an OOPS or structured programming language similar to C ++ or C, while JavaScript is a client-side scripting language called unstructured programming.

3. Which is faster, JavaScript or ASP?

JavaScript is faster. JavaScript is a client-side language, so it does not require the assistance of a Web server to execute. ASP, on the other hand, is a server-side language and is always slower than JavaScript. It’s worth noting that Javascript is now also available for server-side languages (NodeJS).

4. What is negative infinity?

Negative infinity is a number in JavaScript that can be obtained by dividing a negative number by zero.

5. How to break JavaScript code into lines?

This can be done in string statements by using a backslash “” at the end of the first line.

Example: document.write(“This is a program”)

If it is not changed to a new line in a string statement, javaScript ignores breakpoints in the line.

Var x=1, y=2, z= x+y

The code above is perfect, but it is not recommended because it hinders debugging.

6. What are undeclared and undefined variables?

An undeclared variable is one that does not exist and is not declared in a program. If a program tries to read the value of an undeclared variable, it encounters a runtime error.

An undefined variable is a variable declared in a program that has not yet been given any value. If a program tries to read the value of an undefined variable, the undefined value is returned.

7. What are global variables? How are these variables declared, and what are the problems with using global variables?

Global variables are variables that are available for the entire length of the code, that is, they have no scope. The var keyword is used to declare local variables or objects. If the var keyword is omitted, a global variable is declared.

// Declare a global globalVariable = “Test”

The problem with using global variables is a conflict between local and global variable names. In addition, it is difficult to debug and test code that depends on global variables.

8. Explain how timers work in JavaScript? If so, can also explain the disadvantages of using timers?

Timers are used to execute a piece of code at a set time, or to repeat the code at a given time interval. This is done using the functions setTimeout, setInterval, and clearInterval.

The **setTimeout (function, delay) ** function is used to start a timer that invokes a particular function after the delay.

The **setInterval (function, delay) ** function is used to repeatedly perform a given function in the mentioned delay, stopping only when cancelled.

The **clearInterval (id) ** function tells the timer to stop.

Timers run in a thread, so events may need to be queued for execution.

9. What is the difference between ViewState and SessionState?

“ViewState” is specific to the page in the session.

“SessionState” is specific to user-specific data that is accessible on all pages in the Web application.

10. What is the === operator?

=== is called the strict equality operator, which returns true if two operands have the same value without any type conversion.

11. What are loop structures in JavaScript?

For, while, do-while loops

12. How to convert a base string to an INTEGER in JavaScript?

The parseInt() function parses a string argument and returns an integer with a specified cardinality. ParseInt () takes the string to be converted as its first argument, and the second argument is the basis for the given string. To convert 4F (base 16) to an integer, the code used is: parseInt(“4F”, 16)

13. Explain the difference between “==” and “===”?

“==” only checks for equality, whereas “===” is a more rigorous equality test and returns false if two variables have different values or types.

What is the result of 14.3+2+ “7”?

Since 3 and 2 are integers, they’ll just add up. Since 7 is a string, it will be concatenated directly, so the result will be 57.

15. Describe how to check the operating system on the client machine.

To detect the operating system on the client machine, use the Avigator.appVersion string (property).

16. What does NULL in Javascript mean?

NULL is used to indicate that there is no value or object. It means no objects or empty strings, no valid booleans, no numeric and array objects.

17. What does the delete operator do?

The delete operator is used to delete all variables or objects in a program, but not variables declared using the VAR keyword.

18. What types of pop-up boxes are available in JavaScript?

Alert, Confirm and Prompt

19. How to use Void (0)

Void (0) is used to prevent page refreshes and to pass the argument “zero” when called. Void (0) is used to call another method without refreshing the page.

20. How do I force a page to load other pages in JavaScript?

The following code must be inserted to achieve the desired effect:

21. What does the escape character do?

Escape characters (backslashes) are used when special characters (such as single quotes, double quotes, apostrophes, and ampersands) are used. Place a backslash before a character to make it appear. Ex. :

22. What are JavaScript cookies?

Cookies are used to store small test files on a computer and are created when users visit a web site to store the information they need.

Explain the pop () method in JavaScript?

The pop () method is similar to the shift () method, except that the Shift method works at the beginning of the array. In addition, the pop () method takes the last element out of the given array and returns it. Then change the array being called.

Ex. :

Var cloths = [” Shirt “, “Pant”, “TShirt”];

cloths.pop();

//Now cloth becomes Shirt,Pant

24. What are the disadvantages of using innerHTML in JavaScript?

If you use innerHTML in JavaScript, the disadvantages are:

1) Content is everywhere;

2) Cannot be used as “append to innerHTML”;

3) Even if you use + = like “innerHTML = innerHTML +’ HTML ‘” the old content will still be replaced by HTML;

4) The entire innerHTML content is reparsed and built into elements, so it’s much slower;

5) innerHTML does not provide validation, so we might insert valid and destructive HTML into the document and break it.

25. What do break and continue statements do?

The break statement exits from the current loop.

The continue statement continues the next loop statement.

26. What are the two base groups of dataypes in JavaScript?

Primitive

Reference types

The primitive types are numeric and Boolean data types. Reference types are more complex types, such as strings and dates.

27. How do I create generic objects?

Generic objects can be created as:

var I = new object();

28. What does the operator type do?

“Typeof” is an operator that returns a string description of a variable type.

29. Which keywords are used to handle exceptions?

try… Catch-finally is used to handle exceptions in JavaScript.

30. How many different types of errors are there in JavaScript?

There are three types of errors:

**Load time errors: ** This error occurs when a web page is loaded, such as a syntax error. It is called a Load time error and dynamically generates an error.

**Run time errors: ** Errors caused by misuse of commands in HTML.

**Logical Errors: ** This is an error due to incorrect logic being executed on functions with different operations.

31. What is the Push method used in JavaScript?

The push method is used to add or append one or more elements to the end of an array. Using this approach, you can append multiple elements by passing multiple parameters.

What is the unshift method in JavaScript?

The Unshift method is like the push method that works at the beginning of an array. This method is used to add one or more elements to the beginning of an array.

33. How are object attributes assigned?

Attributes are assigned to objects as follows:

Obj [“class”] = 12 or obj.class = 12

Explain window.onload and onDocumentReady?

The onload function is not run until all the information on the page has been loaded. This causes a delay before any code can be executed.

OnDocumentReady loads the code after loading the DOM. This allows for early code manipulation.

35. How would you explain closures in JavaScript? When to use it?

Closure is a locally declared variable associated with a function that remains in memory when the function returns.

36. How does a value attach to an array?

Values can be appended to arrays in a given way:

arr[arr.length]=value

37. Explain the for-in loop?

For-in loops are used to loop over properties of objects.

The syntax for a for-in loop is:

In each loop, an attribute from the object is associated with the variable name, and the loop continues until all the attributes of the object are exhausted.

38. Describe anonymous functions in JavaScript?

Functions that are declared without any named identifiers are called anonymous functions. Generally, anonymous functions cannot be accessed after they have been declared. Anonymous function declarations:

39. What’s the difference between call () and.apply ()?

The.call () and.apply () functions are very similar in use, with a few differences. Use.call () when the programmer knows the number of function arguments, because they must be referred to as arguments in the calling statement. On the other hand, the.apply () function is used when you don’t know the numbers and expects an array. The basic difference between.call () and.apply () is passing arguments to functions. Their use can be illustrated by a given example.

40. Define event bubbling?

JavaScript allows DOM elements to be nested together. In this case, if you click on the child’s handler, the parent’s handler will do the same.

41. What kind of Boolean operators can be used in JavaScript?

“And” operator (&), ‘Or’ operator (| |) And ‘Not’ operator (!) It can be used in JavaScript.

The * operator does not have parentheses.

42. What’s the difference between web-garden and Web-farm?

Web-garden and Web-Farm are web hosting systems. The only difference is that Web-garden is a setup with many processors in a single server, while Web-farm is a larger setup that uses multiple servers.

43. How do I assign object attributes?

Attributes are assigned to objects in the same way that values are assigned to variables.

For example, the action value of the form object is assigned “submit” as follows: document.form.action = “submit”

44. What are the methods for reading and writing files in JavaScript?

This can be done by opening an example of a file using a JavaScript extension (run from the JavaScript editor) :

fh=fopen(getScriptPath(), 0)

45. How do I use DOM in JavaScript?

DOM represents the document object model and is responsible for the interaction of various objects in the document. DOM is required to develop web pages, including objects such as paragraphs, links, and so on. These objects can be manipulated to include operations such as add or remove, and DOM needs to add additional functionality to web pages. In addition, the use of APIS has advantages over others.

46. How are event handlers used in JavaScript?

An event is an action that results from a user-generated activity, such as clicking a link or filling out a form. An event handler is required to manage the proper execution of all these events. Event handlers are additional properties of the object. This property includes the name of the event and the action taken when the event occurs.

47. Explain the role of deferred scripting in JavaScript.

By default, parsing of the HTML code is paused during page loading until the script stops executing. This means that web pages can be delayed if the server is slow or the script is particularly heavy. With Deferred, the script delays execution until the HTML parser runs. This reduces the load time of web pages, and they display faster.

48. What are the various functional components in JavaScript?

The different functional components in JavaScript are:

First-class functions: Functions in JavaScript are used as first-class objects. This usually means that these functions can be passed as arguments to other functions, returned as values of other functions, assigned to variables, or stored in data structures.

Nested functions: Functions defined within other functions are called nested functions.

Explain the unshift () method?

This method works when an array is started, unlike push (). It adds the required number of elements to the top of the array. Such as:

The output is as follows: [” Joseph “, “Jane”, “Charlie”, “John”]

50. What decodeURI () and encodeURI () are?

EncodeURl () is used to convert urls to hexadecimal codes. DecodeURI () is used to convert the encoded URL back to normal.

51. Why not use innerHTML in JavaScript?

The innerHTML content is refreshed every time, so it is slow. There is no room for validation in innerHTML, so it is easier to insert error code into the document, making the page unstable.