Home  >  Article  >  Web Front-end  >  Summary of confusing aspects of basic JavaScript syntax_Basic knowledge

Summary of confusing aspects of basic JavaScript syntax_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:53:24826browse
Copy code The code is as follows:

/*
Among the basic syntax of JS, some are easier to understand Where people are confused.
*/
/*
==
===
*/
function de() {
var ab = 25; //Value
var ba = "25"; //String
if (ab == ba) { //==, it will be converted first and then compared.
//alert("b");
}
if (!(ab === ba)) { //=== will not be converted, but will be compared directly, ab is a numeric type data, and ba is string type data
//alert("a");
}
}
/*
!b
!!b
*/
function dd() {
var b= 1;
if (!!b) { //! When it is a non-zero value, it returns false. When !!, it goes further boolean() method, and then negate the Boolean value, so the value itself is obtained.
//alert("a");
}
}
/*
parseInt parseFloat
*/
function parse() {
var a = " 18px";
var b = parseInt(a); //Return the value 18
var c = parseInt(a, 10); //Return the value 18, you can pass parameters, base
//alert (b);
alert(c);
var e = "18.2px";
var d = parseFloat(e);
alert(d)
/*
parseInt The difference from parseFloat is that when parseFloat converts a value, it will not ignore the first decimal point. That is to say, the number after the first decimal point will be retained, but the second decimal point will be ignored.
parseFloat also ignores 0 at the first position.
*/
}
window.onload = function () {
parse();
dd();
de();
}
Statement:
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