3 questions per day (23)

2020/3/26

problem

html: js on the html <body>and <head>what is the difference?

css: What is BFC? What triggers BFC?

js: What are the differences between let, const, and var?

html: js on the html <body>and <head>what is the difference?

js put head, if you do not add asyncor defertime, when the browser encounters script, the building blocks the DOM tree, thereby affecting the page is loaded. When there are many js files, the time of the page blank screen will also become longer. Js into the <body>inside (typically </body>at the top), because when the DOM order parsing, and therefore without blocking the DOM js analysis. For must be resolved before the DOM is necessary to load the js, we need to put <head>in.

css: What is BFC? What triggers BFC?

What is BFC

BFC is called Block Formatting Context. BFC is a concept in the W3C CSS 2.1 specification. It determines how an element positions its content and the relationship and interaction with other elements. When it comes to visual layout, Block Formatting Context provides an environment in which HTML elements are This environment is laid out according to certain rules. Elements in one environment will not affect the layout in other environments. For example, a floating element will form a BFC. The child elements inside the floating element are mainly affected by the floating element, and the two floating elements do not affect each other. This is similar to the meaning of a BFC is an independent administrative unit. It can be said that BFC is a scope, and it is understood as an independent container, and the layout of the box in this container has nothing to do with the box outside this container.

Conditions that trigger BFC

  • Root element or other element containing it
  • Floating elements (elements floatnot none)
  • Absolutely positioned elements (elements with positionas absoluteor fixed)
  • Inline block (element has display: inline-block)
  • Table cells (element has the display: table-celldefault attributes of HTML table cells)
  • Table title (element has display: table-caption, HTML table title default attribute)
  • With overflowand not the value of visiblethe block element
  • Flexible box ( flexor inline-flex)
  • display: flow-root
  • column-span: all

Tomorrow use

js: What are the differences between let, const, and var?

Declaration method Variable promotion Temporary dead zone Repeat statement Block-level scope is valid
where meeting does not exist allow No
let will not presence Not allowed Have
const will not presence Not allowed Have

1. Variables defined by let / const will not be promoted, while variables defined by var will be promoted.

2. In the same scope, let and const do not allow repeated declarations, var allows repeated declarations.

3.const must set the initial value when declaring variables

const a;
// 报错

4.const declare a read-only constant, this constant can not be changed.

There is a very important point here: in JS, complex data types, stored in the stack is the address of the heap memory, the address stored in the stack is unchanged, but the value stored in the heap can become . Is there a fairly constant pointer / pointer constant ~

const arr = [1,2,3];
arr[0] = 10;
// arr [10, 2, 3]

Temporary dead zone


Source of the question

Published 49 original articles · Like1 · Visits 1088

Guess you like

Origin blog.csdn.net/weixin_44194732/article/details/105113757