React.js学习之codecademyJSX测试

1.Question:What's a difference between a DOM object and a virtual DOM object?

    Answer:A virtual DOM object can update much faster than a regular DOM object.

                 A virtual DOM object can't directly affect HTML.

                A virtual DOM object will be updated if ANY JSX element renders.

2.Question:What is the correct way to attach the function 'yo' to a click event?

let yo = () => {
  alert('Yo');
};

    Answer:

<button onClick={yo}></button>

3.Question:What's wrong with this code?

let skateboardDog = (
  <img src="alfie.jpg" />
  <h1>Hiya kids!  I'm a dog on a skateboard.</h1>
);

    Answer:JSX expressions need an outermost element.

4.Question:What should you pass to ReactDOM.render() for its second argument?

    Answer:A selector that matches an HTML element.

5.Question:What problem does the virtual DOM attempt to solve?

    Answer:Updating DOM objects happens unnecessarily often.

6.Question:Which will render "100" to the screen?

    Answer:

ReactDom.render(
  <h1>{10 * 10}</h1>, 
  document.getElementById('app')
);

7.Question:What should you pass to ReactDOM.render() for its first argument?

    Answer:A JSX expression that you want to render.

8.Question:Place the following steps in the right order:

                  a. The screen looks different than it used to.

                  b. A JSX element renders.

                  c. The virtual DOM "diffs," comparing its current self with its previous self.

                  d. The entire virtual DOM updates.

                  e. Part of the real DOM updates. 

    Answer:b, d, c, e, a

9.Question:Can a web browser read JSX directly?

    Answer:No, JSX must be compiled before it can be read by a web browser.

猜你喜欢

转载自blog.csdn.net/jjy8040/article/details/86228546
今日推荐