Home > Web Front-end > JS Tutorial > JavaScript special statements and usage

JavaScript special statements and usage

高洛峰
Release: 2016-11-28 11:08:06
Original
1092 people have browsed it

JavaScript is a scripting language commonly used in front-end development. I have compiled some rare usages


1. Closures, which have the advantage of avoiding variable pollution. Many js frameworks (such as jQuery) and plug-ins use closures to implement
(function(args1, args2...){ //js code})(args1, args2...);
Equivalent writing: !function(){ //js code}(); // Not recommended , there may be compatibility issues


2. Comma expression, you can combine multiple statements into one statement
Return alert('ha ha!'),!1; //Comma expression, the value is the last expression The value of || b1;

alert(typeof a1 + "," + typeof b1 + "," + typeof c1); // Types are all numeric types



var a2 = !1, b2 = !0;
var c2 = a2 || b2;
alert(typeof a2 + "," + typeof b2 + "," + typeof c2); // The types are all Boolean types


4, clever use of void 0 (equivalent to undefined)
var a = void 0; // void 0 is undefined, with strong compatibility
var b = undefined; // The undefined value can be overwritten. If undefined = 'abc' is added, b is also equal to 'abc'



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template