Front-End Pen Question----javascript section

Source: Internet
Author: User
Tags string to json

1. What are the built-in objects of js?

Object Name Object description
Arguments Function Parameter Collection
Array Array
Boolean Boolean Object
Date Date Time
Error Exception Object
Function function constructors
Math Mathematical objects
Number Numeric objects
Object Base Object
Regexp Regular Expression objects
String String Object

2. What is the understanding of this object?

  

3. What does eval do?

The eval () function computes a string and executes the JavaScript code in it.

<script type= "text/javascript" >eval("x=10;y=20;document.write (x*y)") document.write (eval ( "x=10")var document.write (eval (x+17)) </script>// output:200427

4. How does the DOM add, remove, move, copy, create, and find nodes?

Some common HTML DOM methods:

    • getElementById (id)-gets the node (element) with the specified ID
    • AppendChild (node)-insert A new child node (element)
    • RemoveChild (node)-delete child Nodes (elements)

Some common HTML DOM properties:

    • InnerHTML-text value of the node (element)
    • Parentnode-parent node of the node (element)
    • ChildNodes-child nodes of Nodes (elements)
    • Attributes-node (element) Attribute Node

CloneNode () Copy Node

5. What is the difference between null and undefied?

Undefined value representing the variable declaration but not initialized

Null means that the object is ready to be saved, and the value of the object is not actually saved. From a logical point of view, a null value represents an empty object pointer

Null is an object that represents "none", and a value of 0;undefined is a primitive value that represents "none", and a value of Nan when converted to a number.

number (undefined) // nan5 + undefined//  nan

Null + 5
5

Null

(1) as a function parameter, the parameter of the function is not an object.

(2) as the end point of the object prototype Chain.

Undefined

(1) the variable is declared, but when it is not assigned, it is equal to Undefined.

(2) when calling a function, the argument that should be supplied is not provided, which equals undefined.

(3) The object does not have an assigned property, and the value of this property is Undefined.

(4) when the function does not return a value, undefined is returned by Default.

object.getprototypeof (object.prototype) // NULL var  //  undefinedfunction//  undefinedvar  New//  undefinedvar x =//  Undefined

Http://www.ruanyifeng.com/blog/2014/03/undefined-vs-null.html

6. What does the new operator do specifically?

first, a simple instance of the new operator

var function (name) {    this. name = name;       this function () {        returnthis. name;    };} var New Person ("nyf"); Nyf.say ();
Simply put, in the above example, when the constructor is called with the new operator, the following changes occur within the Function: 1, create an empty object, and the This variable references the object, and also inherits the prototype of the Function.  2, properties and methods are added to the object referenced by This. 3. The newly created object is referenced by this and the last implicitly returns This. The above is called by the new operator and the background is the equivalent of
var function (name) {    //var this = {};    this. name = name;      this function () {        returnthis. name;    };     // return this;}
I do not know whether or not to speak clearly.
var New Base ();
Equivalent to running the following code
var obj == base.prototype; Base.call (obj);
For ES5, the object.create () is added,
if (typeof object.create!== "function") {    function(o) {        function  F () {};         = o;         return New F ();    }}

7. What is json?

It is a kind of lightweight data interchange format, It is an ideal data exchange format with completely language-independent text format. At the same time, JSON is a native JavaScript format, which means that working with JSON data in JavaScript does not require any special APIs or Toolkits.

This article is mainly to the JS operation JSON Essentials to do a summary.

In json, there are two kinds of structures: objects and Arrays.

1. An object starts with "{" (opening Parenthesis) and "}" (the closing Parenthesis) ends. Each "name" is followed by a ":" (colon); "' name/value ' pairs" are separated by "," (comma). The name is enclosed in quotation marks, and if the value is a string, it must be in parentheses, and the numeric type is not Required. For example:

var o={"xlid": "cxh", "xldigitid": 123456, "topscore": $, "topplaytime": "2009-08-20"};

2. An array is an ordered collection of values (value). An array begins with "[" (the left square bracket), and "]" (the right square bracket) ends. Use "," (comma) to separate values.

For example:

var jsonranklist=[{"xlid": "cxh", "xldigitid": 123456, "topscore": $, "topplaytime": "2009-08-20"},{"xlid": "zd", " Xldigitid ": 123456," topscore ":" topplaytime ":" 2009-11-20 "}];

To facilitate the processing of JSON data, JSON provides the json.js package: http://www.json.org/json.js

In the data transfer process, JSON is passed in the form of text, which is a string, and JS operates on a JSON object, so the conversion between the JSON object and the JSON string is Key. For example:

JSON string:

var str1 = ' {' name ': ' cxh ', ' sex ': ' man '} ';

JSON object:

var str2 = {"name": "cxh", "sex": "man"};

one, JSON string converted to JSON object

To use the above str1, you must use the following to turn the lead into a JSON object:

Convert from JSON string to JSON object

var obj = eval (' (' + str + ') ');

Or

var obj = Str.parsejson (); Convert from JSON string to JSON object

Or

var obj = Json.parse (str); Convert from JSON string to JSON object

then, you can read this:

Alert (obj.name);

Alert (obj.sex);

Special Attention: If obj is originally a JSON object, then the use of the Eval () function after conversion (even If multiple CONVERSIONS) is a JSON object, but the use of the Parsejson () function will be problematic (throwing a syntax exception).

second, You can use tojsonstring () or global Essentials json.stringify () to convert the JSON object into a JSON string.

For example:

var last=obj.tojsonstring (); Convert a JSON object to a JSON character

Or

var last=json.stringify (obj); Convert a JSON object to a JSON character

Alert (last);

Pay attention:

In the above multiple essentials, in addition to the Eval () function is JS comes from, the other main points are from the json.js package. The new version of JSON modifies the API to inject json.stringify () and json.parse () two essentials into the Javascript built-in object, which becomes the object.tojsonstring (), and the latter becomes the Strin G.parsejson (). If you are prompted not to find the tojsonstring () and Parsejson () essentials, your JSON package version is too low.

8, call () and apply () the difference and role?

Each function object in JavaScript has an apply method:

function. Apply ([thisobj[,argarray]])

There is also a call method for similar functionality :

function. Call ([thisobj[,arg1[, arg2[, [,. argN]])

Their respective definitions:

Apply: One method of applying an object that replaces the current object with another Object.

Call: invokes one method of an object, replacing the current object with another Object.

What they have in common:

Used instead of another object to invoke a method that changes the object context of a function from the initial context to the new object specified by thisobj. "

The difference between them:

Apply

There can be a maximum of two parameters-the new this object and an array argarray. If you pass multiple arguments to the method, the arguments are written into the array, and of course, even if there is only one argument, it is written into the Array. If Argarray is not a valid array or is not a arguments object, it will result in a TypeError. If none of the Argarray and thisobj parameters are provided, then the Global object is used as a thisobj and cannot be passed any Parameters.

Call

is a direct parameter list, mainly used in the JS object Each method calls each other, so that the current this instance pointer is consistent , or in special cases need to change the this pointer. If the thisobj parameter is not provided, then the Global object is used as the thisobj.  

To put it simply, theapply and call functions are just the same as the parameter list passed in: for example, func.call (func1,var1,var2,var3), The corresponding apply is written as: Func.apply (func1,[var1,var2,var3])

That is, call is a single, and the parameter called by apply is an array

function sum (a, b) {    console.log (this = = window);   true    console.log (a + b);} sum (sum.call); Sum.apply (null, [+]);

Role

a, calling a function

var info = ' Tom '; function foo () {    //    var info = ' Jerry ';    Console.log (this. info);  // Tom    Console.log (this ===window)   //true

b, call, and apply can change the direction of this in the function

var obj = {        info:' spike '};foo.call (obj);     // this in the Foo function points to the objfoo.apply (obj);

c, use the method of other objects to find the maximum value in the array
var arr = [123,34,5,23,3434,23]; // Method One var arr1 = Arr.sort (function(a, b    ) {return b-a;}); Console.log (arr1[0]); // Method Two var max = Math.max.apply (null, Arr)   // method of borrowing other objects Console.log (max);

9. How to get ua?

10. What are the differences between Java and javascript?

11. What are your performance optimization methods?

http://blog.csdn.net/mahoking/article/details/51472697

12. What common operations can cause memory leaks?

Http://www.cnblogs.com/chuaWeb/p/5196330.html

13. What are the differences between threads and processes?

A thread is a part of a process that contains multiple threads running

A program has at least one process, and a process has at least one thread.

Child processes and parent processes have different code and data spaces, while multiple threads share data spaces, and each thread has its own execution stack and program counter for its execution context. Multithreading is mainly to save CPU time, play use, depending on the Situation. The running of a thread requires the use of the Computer's memory resources and CPU.

Front-End Pen Question----javascript section

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.