Introduction

I believe there are a lot of people like me are halfway front-end development, when it is to find a training institution to train a four or five months out to find a job, so the basic part of the front-end Js mastery is very weak, although the work is found, but in the daily work of many problems encountered do not know how to solve or do not know how to generate, are not firm foundation, so I want to turn comb front-end JS basic part, also recorded, remember to write a note may deepen their understanding and memory, but also hope to help students in need;

I am also watching the video while combing, see where combing to where, but also will continue to slowly improve. There are incomplete places or incorrect places welcome to point out the discussion. Thank you ~

1.Create variable way of

Definition of a variable as a container for storing specific values, the stored values can be changed at any time;

1
2
3
4
5
6
7
1. var name = 'name'; create variable
2. let name = 'name'; create variable
3、const name = 'name'; create constant
4、function () {}; create function
5、import exported module information
6、class create class
(For import create variables I do not understand very well, should be the introduction of the exported module, create a name to store the information of the imported module;)

2. Data type

1
2
3
4
5
6
Basic data type.
number(number NAN is a number type, but not a number)
string(String)
boolean(Buur)
null
undefined
1
2
3
Introduce data types.
Object (ordinary object, array object, time object, regular object, etc.)
function(function)
1
2
Symbol (es6's new base data type) unique value
(I've never used it, it's a separate data type, a unique value, similar to something like ID)

3. Digital type

Type conversion

1
2
3
4
5
6
Conversion by Number() method
Conversion of basic types
1. Number([string]); if any one non-valid number appears in the string, the result is NAN;
2、Number([Boolean]); true = 1; false = 0.
3、Number([null]) = 0.
4、Number([undefined]) = NaN.
1
2
3
4
5
6
Reference type
first the value of the reference type .toString() to a string, and then in the string Number() to a number;
1, object.toString() => [Object, Object] => NaN
2, array [1, 2].toString() => '1, 2' => NaN
3, array[1].toString() => '1' => 1
4. array[].toString() => '' => 0

Parsing string numbers

1
2
3
find a valid number starting from the leftmost character of the string and convert it to a valid numeric character, ending the search when a non-valid numeric character is encountered;
parseInt: parse the integer part of the string parseInt('1.5px') => 1
parseFloat: parse the part of the string that contains a decimal number parseInt('1.5px') => 1.5

Comparison of NaN

NaN is not equal to anyone, including itself; if (NaN == NaN) => false.

Boolean types

true and false have only two values; true = 1 false = 0;
Only 0, null, undefined, NaN, and empty string are false in js, the rest are true

5.null && undefined

null means null object pointer
undefined means undefined

6. Common methods for arrays

1、push => Add new content to the last item of the array. The return value is the length of the array after adding;
2、pop => Delete the last item of the array. The return value is the content of the deleted item;
3、shift => Delete the first item of the array. The return value is the content of the deleted item; 4. unshift => Add new content to the start of the array. The return value is the length of the array after it is added;
5、splice
delete arr.split(n, m)
Delete m contents from index n. Returns a new array with the contents removed; if m is not passed, the array is removed from n to the end of the array;
Add arr.split(n, 0, m)
remove 0 items from index n and add m items to the front of index n; returns the empty array;
Modify arr.splice(n , m , x)
start from index n, delete m items, insert x items in front of n; return to delete the array.

slice
slice(n, m) from the index n, find the index m, excluding the index m; return to find the new array
7、concat
splice array, you can spell value or array; return value is a new array of splice

1
2
3
4
5
let arr1 = [1, 2, 3], arr2 = [11, 22, 33];
console.log((arr2)arr.concat(arr2)) = [1, 2, 3, 11, 22, 33];
arr1.concat('hello', arr2) = [1, 2, 3, "hello", 11, 22, 33];
[].concat(arr1, arr2) = [1, 2, 3, 11, 22, 33];