English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript学习笔记整理_关于表达式和语句

Espressioni e istruzioni

eval( ) ha solo un parametro

Quando il parametro non è una stringa, viene restituito direttamente questo parametro;

Quando il parametro è una stringa, essa viene considerata come codice JavaScript per la compilazione; se la compilazione fallisce, viene lanciata un errore di sintassi; se la compilazione ha successo, viene eseguito il codice e restituito il valore dell'ultima istruzione, se non c'è un valore, viene restituito undefined

eval() utilizza l'ambiente di scope della variabile che lo chiama

Il parametro di stringa che riceve, quando è usato come codice indipendente, deve avere un significato, altrimenti il compilazione fallisce

Operatore delete: utilizzato per eliminare attributi liberi degli oggetti, elementi degli array

Dopo aver eliminato un attributo, l'attributo non esisterà più, mentre dopo aver eliminato un elemento dell'array, resterà una buca con un valore undefined nell'array, la lunghezza dell'array non cambia;

Se si tenta di eliminare un attributo non eliminabile, viene restituito false; se l'eliminazione ha successo o l'operazione non ha avuto effetto, viene restituito true

Non è possibile eliminare con delete:

1、Impossibile eliminare attributi integrati e proprietà client

2、Le variabili dichiarate dall'utente con la statement var non possono essere eliminate;

3、Le funzioni e i parametri delle funzioni definite con la statement function non possono essere eliminati

4、Impossibile eliminare attributi non configurabili

Operatore void: l'operando viene eseguito normalmente, ma il suo valore viene ignorato e restituito undefined

void ha le seguenti funzioni:

* Utilizzare void 0 per ottenere undefined è più affidabile e sicuro rispetto all'uso di undefined letterale;

* Assicurarsi che l'href di <a> non causi uno spostamento della pagina quando viene cliccato; assicurarsi che la src di <image> non invii richieste inutili al server. href='javascript:void(0);'

Regardless of whether the break statement is labeled or not, its control cannot cross the boundary of the function! That is, you cannot jump from the inside of the function to the outside of the function

Object.create( p , [x] )

This method creates a new object with object p as the prototype and returns it, the optional x is used for further description of object properties

var p1 = Object.create(p); // Create a new object p1 that inherits from object p (using p as the prototype)

That is, the value of p1's prototype (prototype) property is p

The difference between P.x and P['x']:

When accessing P.x, it can only access the property named x

While P['x'] is more flexible, it can dynamically modify the value of the string inside [ ] to access different properties, such as P['x'+i]

The magic of logical '&&', '||' and short-circuit behavior

Through &&, it ensures that before reading the length attribute, both book and book.subtitle are true values, i.e., objects

var len = book && book.subtitle && book.subtitle.length;

Ensure that the value of x is: the first true value from a~f, ignoring the subsequent true values

var x = a || b || c || d || e || f;
 
if(!buy){...} When buy is a false value, execute {...}

To get an equivalent boolean value through !!x

This is the full content of the JavaScript learning notes compiled by the editor about expressions and statements, I hope it will be helpful to everyone, please support the shouting tutorial~