Baidu frontend test interview 7 questions

Source: Internet
Author: User

1. What data types does JavaScript contain?

There are two types of answers: Basic Types and objects. The basic types include numbers, strings, Boolean and null, and objects (similar to objects ), including arrays, functions, built-in objects, and custom objects. However, strings also have some characteristics of objects.

My answer is based on the Javascript authoritative guide. For some minor issues, undefined is missing in the first class.

After searching, there are several answers on the Internet:

First:There are nine types: 1. undefined (undefined) 2. null 3. boolean (Boolean) 4. string (string) 5. number (number) 6. object 7. reference 8. list 9. completion ). The reference, list, and completion types are data types that serve as intermediate results during Javascript runtime and cannot be used in code.

I have never seen it.

Second:Javascript contains six data types: undefined, null, String, number, Boolean, and object. Among them, the first five are the original data type, and the object is the object type. The object types include object, function, String, number, Boolean, array, Regexp, date, globel, math, and error, and the object types provided by the host environment.

Except for reference, list, and completion, these answers are similar.

2. What are the similarities and differences between alt and title?

I saw such an article a few days ago. These two attributes are repeated. The performance varies in different browsers. When both ALT and title are set, ALT is used as an alternative text for the image. title is the interpreted Text of the image.

I just made a small experiment. When there is no title, ALT will be interpreted as an image, but Firefox does not seem to do this. If the test is complete, it is complicated to store images that do not exist, only the title, only ALT, 2*2*2, and 8 cases.

3. Rewrite border-color-left, marin-left, and-moz-viewport to JavaScript format.

This is-there is no problem with changing the upper-case character. The third-Moz is really uncertain. (To be continued)

Ps: I just received a call from Baidu for an interview. After waiting for a long time, I thought I had no hope. Please be happy. However, I do not have many advantages, either in terms of technology or experience. There is only one disadvantage and no advantage, but rp is okay ). I was lucky to pass the test, but I had little hope to go to Baidu.

Continue: I tested a-moz-border-radius which is indeed written as mirror borderradius.

4. Compile a JavaScript function to display the current time in real time. Format: "year-month-day hour: minute: second"

It mainly uses various Time functions, setInterval (funtionName, Time), and firstChild. nodeValue.

The setInterval function name seems to be wrong. I wrote the most common and simplest function, and retrieved the time every second. There are many points worth optimizing. If the program is not easy to write, it will not be ugly.

5. Use css and html to compile a webpage with two columns of layout. The right side width must be PX and the left side will be automatically expanded.

My main idea is absolute positioning on the right side. The right side of the Left box is 200px, and the right side is empty.

The css I wrote is as follows:

#right{
  position:absolute;
  right:0;
  width:200px;
}
#left{
  marin-right:200px;
}

Another method (experimental ):

#right{
  float:right;
  width:200px;
}
#left{
  marin-right:200px;
}

In HTML code # right must be written before # left

<body>
  <div id=”right”>…</div>
  <div id=”left”>…</div>
</body>

This seems to be a classic interview question, which was asked during an interview. Another classic question is how to center a fixed-width div on the page.

6. How can I use JavaScript to deeply clone an object?

The value of var anObj = anOtherObj for an object in JavaScript is the address transfer method and cannot be used to copy objects.

Object prototype writing is more universal, but prototype was not very good at that time. Only a clone function was written. I just checked it out and it was really tricky. The following is the implementation code:

function Object.prototype.cloneObj()
{
  function NEWOBJECT(){};
  NEWOBJECT. prototype = this;
  var anObj = new NEWOBJECT();
  for ( var ele in anObj )
  {
   if ( typeof anObj[ele] == “object” ) return anObj[ele]. cloneObj();
  }
  return anObj;
}

7. Linux: delete files with the suffix. c in the current directory in batches, such as a. c and B. c.

My answer is rm *. c.

Fortunately, I have a little bit of linux basics, but I also owe it to my previous review of several common linux commands.

Additional questionsIt is the AS question of Flash. It is about the similarities and differences between AS2.0 and AS3.0 in Object-Oriented aspects. I have never been in touch with the AS for a long time. I didn't answer this question.

From: http://www.webjx.com/javascript/jsajax-17997.html

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.