JavaScript basic Question Bank

Source: Internet
Author: User
Tags html comment javascript extension set time setinterval

Select title:

Fill in the blanks questions:

Question and Answer question:

1. What is JavaScript? (This is the basic problem, for many programmers is also send sub-problem!) )

JavaScript is a client and server-side scripting language that can be inserted into an HTML page and is currently the more popular web development language. At the same time, JavaScript is an object-oriented programming language.

Similar basic topics include: What types of JavaScript are there? Who Invented JavaScript? ......

2. List the differences between Java and JavaScript?

Java is a very complete and mature programming language. In contrast, JavaScript is a programming language that can be introduced into HTML pages. The two languages are not completely interdependent, but are designed for different purposes. Java is an object-oriented programming (OOPS) or structured programming language, similar to C + + or C, while JavaScript is the client-side scripting language, which is called unstructured programming.

3. Which is faster than JavaScript and ASP scripting?

JavaScript is faster. JavaScript is a client language, so it does not require the assistance of the Web server to execute. ASP, on the other hand, is a server-side language and is always slower than JavaScript. It is important to note that JavaScript is now also available for server-side language (NODEJS).

4, what is negative infinity?

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

5, how to break down the JavaScript code into a few lines?

In a string statement, you can do this by using the backslash "\" at the end of the first line.

Example: document.write ("This was \a program");

If you do not change to a new line in a string statement, JavaScript ignores the breakpoint in the row.

Cases:

var x=1, y=2,

z=

X+y;

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

6. What are non-declared and undefined variables?

A variable that is not declared is a variable that does not exist in the program and is not declared. If the program tries to read the value of an undeclared variable, it encounters a run-time error. A variable that is not defined is a variable declared in the program but not given any value. If the program attempts to read the value of an undefined variable, an undefined value is returned.

7. How can I write code that dynamically adds new elements?

8. What is a global variable? How are these variables declared and what are the problems with using global variables?

Global variables are variables that are available throughout the length of the code, meaning that these variables have no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.

Example://Declare a global globalvariable = "Test";

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

9. Explain the work of the timer in JavaScript? If so, can you explain the drawbacks of using timers?

A timer is used to execute a piece of code at a set time, or to repeat the code for a given time interval. This is done by using functions Settimeout,setinterval and clearinterval.

    • The SetTimeout (function,delay) function is used to initiate a timer that invokes a specific function after the delay.

    • The setinterval (function,delay) function is used to repeatedly perform a given function in the mentioned delay and only stops when it is canceled.

    • The Clearinterval (ID) function instructs the timer to stop.

The timer runs within a thread, so events may need to be queued for execution.

10. 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 can be accessed on all pages in a Web application.

11. What is the = = = operator?

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

12. How do I submit a form using JavaScript?

To submit a form using JavaScript, use the

Document.form [0]. Submit ();

13. How does the style/class of the element change?

This can be done in the following ways:

document.getElementById ("MyText"). Style.fontsize = "20?;

Or

document.getElementById ("MyText"). ClassName = "Anyclass";

14. What are the looping structures in JavaScript?

For, while, Do-while loops

15. How do I convert a base string to an integer in JavaScript?

The parseint () function parses a string parameter and returns an integer that specifies the cardinality. parseint () takes the string to be converted as its first argument, and the second argument is the basis for the given string.

In order to convert 4F (radix 16) to integers, the code used is: parseint ("4F", 16);

16. Explain the difference between "= =" and "= = ="?

"= =" only checks for values equal, and "= = =" is a more restrictive equality decision, which returns false if the value or type of the two variable is different.

What is the result of 17, 3 + 2 + "7"?

Since 3 and 2 are integers, they will be added directly. Since 7 is a string, it will be connected directly, so the result will be 57.

18, how to detect the operating system on the client machine?

In order to detect the operating system on the client machine, you should use the Navigator.appversion string (attribute).

19. What does null in JavaScript mean?

Null is used to denote no value or no object. It means that there are no objects or empty strings, no valid Boolean values, and no numeric and array objects.

20. What is the function of the delete operator?

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

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

Alert, Confirm and, Prompt

22, Void (0) How to use?

    • Void (0) is used to prevent page refreshes and to pass the parameter "zero" when called.

    • Void (0) is used to invoke another method without refreshing the page.

23. How do I force pages to load other pages in JavaScript?

You must insert the following code to achieve the desired effect:

24. What is escape character used for?

The escape character (backslash) is used when special characters, such as single quotes, double quotes, apostrophes, and symbols, are used. Place a backslash before the character to make it appear.

Cases:

25. What is a JavaScript Cookie?

Cookies are used to store small test files on a computer that are created when a user accesses a website to store the information they need.

26. Explain the Pop () method in JavaScript?

The Pop () method is similar to the shift () method, but the difference is 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. The called array is then changed.

Cases:

var cloths = ["Shirt", "Pant", "Tshirt"];

Cloths.pop ();

Now cloth becomes shirt,pant

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

If you use InnerHTML in JavaScript, the disadvantage is that the content is ubiquitous; it cannot be used as "append to InnerHTML", even if you use + = like "InnerHTML = InnerHTML + ' html '" The old content is still replaced by HTML, the entire innerHTML content is re-parsed and built into elements, so it is much slower and innerHTML does not provide validation, so we may insert valid and destructive HTML into the document and break it.

28. What are the effects of break and continue statements?

    • The break statement exits from the current loop.

    • The continue statement continues to the next loop statement.

29. What are the two basic groups of dataypes in JavaScript?

    • Primitive

    • Reference types

The original type is a numeric and Boolean data type. Reference types are more complex types, such as strings and dates.

30. How do I create a generic object?

Generic objects can be created as:

var I = new Object ();

31. What is the operator type used for?

' Typeof ' is an operator that returns a string description of the variable type.

32. What keywords are used to handle exceptions?

Try ... Catch-finally is used to handle exceptions in JavaScript.

33. What are the different types of errors in JavaScript?

There are three types of errors:

    • Load Time Errors: This error occurs when loading a Web page, such as a syntax error, known as a load-times error, and generates an error dynamically.

    • Run Time errors: Error caused by misuse of command in HTML language.

    • Logical Errors: This is an error that occurs due to the execution of the error logic on a function with a different operation.

34. 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. With this approach, multiple elements can be attached by passing multiple parameters.

35. What is the Unshift method in JavaScript?

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

36. How are object attributes assigned?

The properties are assigned to an object as follows:

Obj["class"] = 12;

Or

Obj.class = 12;

37. What is the way to get checkbox status?

Alert (document.getElementById (' CheckBox1 '). Checked);

This alert returns true if the checkbox is checked.

38, explain Window.onload and ondocumentready?

The onload function is not run until all the information for the page is loaded. This results in a delay before any code execution occurs.

Ondocumentready loads the code after the DOM is loaded. This allows for early code manipulation.

39. How would you explain the closures in JavaScript? When do I use it?

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

For example:

40. How is a value attached to an array?

You can append a value to an array in a given way:

arr [arr.length] = value;

41, explain the for-in cycle?

The for-in loop is used to loop the properties of an object.

The syntax for the for-in loop is:

In each loop, a property from the object is associated with the variable name, and the loop continues until all properties of the object are exhausted.

42. Describe the anonymous function in JavaScript?

A function that is declared as having no named identifiers is called an anonymous function. In general, anonymous functions cannot be accessed after they are declared.

anonymous function declaration:

43. What is the difference between. Call () and. Apply ()?

function. Call () and. Apply () are very similar in use, just a little bit different. When the programmer knows the number of the function arguments, use. Call (), because they must be referred to as parameters in the invocation statement. On the other hand, when you don't know the number, use. Apply (), function. Apply () the expected parameter is an array.

The basic difference between. Call () and. Apply () is to pass parameters to the function. Their usage can be explained by a given example.

44. Define event bubbling?

JavaScript allows DOM elements to be nested together. In this case, if you click the child's handler, the parent's handler will also perform the same work.

45. What Boolean operators can be used in JavaScript?

The "and" operator (&&), the ' Or ' operator (| | ) and the ' Not ' operator (! ) can be used in JavaScript.

The * operator has no parentheses.

46. How does a specific framework use hyperlink positioning in JavaScript?

You can do this by using the "target" property to include the name of the desired frame in the hyperlink.

<a href= "newpage.htm" target= "Newframe" >>new page</a>

47. What is the difference between Web-garden and web-farm?

Both Web-garden and Web-farm are network hosting systems. The only difference is that Web-garden is a setting that contains many processors in a single server, while Web-farm is a larger setting that uses multiple servers.

48. How to assign object properties?

The property is assigned to an object in the same way as the value assigned to the variable. For example, the action value of the Form object is assigned as "' Submit" in the following way: Document.form.action = "Submit"

49. What is the way to read and write files in JavaScript?

You can do this by opening an example of a file by using the JavaScript extension (run from the JavaScript editor):

FH = fopen (Getscriptpath (), 0);

50. How do I use the DOM in JavaScript?

The DOM represents the Document object model and is responsible for interacting with the various objects in the document. The DOM is required to develop Web pages, including objects such as paragraphs, links, and so on. You can manipulate these objects to include actions such as additions or deletions, and the DOM also needs to add additional functionality to the Web page. In addition, the use of APIs is more advantageous than others.

51. How do I use event handlers in JavaScript?

An event is an action that is caused by 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. An event handler is an extra property of an object. This property includes the name of the event and the action taken when the event occurs.

52. Explain the role of deferred scripting in JavaScript?

By default, parsing of the HTML code pauses during page load until the script stops executing. This means that if the server is slow or the script is particularly heavy, it can cause web pages to be delayed. When deferred is used, the script delays execution until the HTML parser runs. This reduces page load times, and they are displayed more quickly.

53. What are the various functional components in JavaScript?

The different functional components in JavaScript are:

    • First-class function: A function in JavaScript is used as the first class object. 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 in other functions are called nested functions.

54, explain the Unshift () method?

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

The output is as follows:

["Joseph", "Jane", "Charlie", "John"]

55. What is decodeURI () and encodeURI ()?

Encodeurl () is used to convert the URL to hexadecimal encoding. The decodeURI () is used to convert the encoded URL back to normal.

56. Why is it not recommended to use innerHTML in JavaScript?

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 codes into the document, which makes the Web page unstable.

57. How do I hide JavaScript code in an old browser that doesn't support JavaScript?

    • In the code after the <script> tag, add "<! -"without the quotation marks.

    • No quotation marks are added to the "//->" code before the <script> tag.

    • The old browser now treats the JavaScript code as a long HTML comment. JavaScript-enabled browsers will "<! -"and"//-> "As a line of comments.

JavaScript basic Question Bank

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.