English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Expressions and statements
eval() has only one parameter
If the parameter is not a string, it returns the parameter directly
When the parameter is a string, it treats the string as JavaScript code for compilation. If compilation fails, a syntax error is thrown. If compilation is successful, the code is executed, and the value of the last statement is returned. If there is no value, undefined is returned
The eval() function uses the scope environment of the variable that calls it
The string parameter it receives must be semantically meaningful when used as standalone code; otherwise, compilation will fail
The delete operator: used to delete the free properties of an object, elements of an array
After deleting a property, the property will no longer exist. After deleting an array element, a hole with a value of undefined will be left in the array, and the length of the array will not change
Attempting to delete an unconfigurable property returns false. If the deletion is successful or the deletion operation has no effect, it returns true
The delete operator cannot delete:
1Built-in core and client properties cannot be deleted
2Variables declared by the user with the var statement cannot be deleted
3Functions and function parameters defined by the function statement cannot be deleted
4Properties that cannot be configured cannot be deleted
The void operator: the operand will execute normally, but will ignore the value of the operand and return undefined
The void operator has the following effects:
* Using void 0 to get undefined is more reliable and secure than using the literal undefined;
* Fill <a> href to ensure that there is no page jump when clicked; Fill <image> src to ensure that no garbage requests are sent to the server. href='javascript:void(0);'
Regardless of whether the break statement has a label 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 the object, the optional x is used for further description of object properties
var p1 = Object.create(p); //Create a new object p1, it inherits from the object p (with p as the prototype)
That is, p1The value of the prototype (prototype) property is p
The difference between P.x and P['x']:
When accessing P.x, it can only access the property with the fixed name 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 book and book.subtitle are both true values before reading the length property, i.e., they are 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){...} Execute {...} when buy is a false value
Use !!x to get an equivalent boolean value
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 and cheer for the tutorial!