web123456

javascript review

  1. \
  2. /*
  3. * :: The data type refers to the type of literals
  4. * There are six data types in JS.
  5. * :: String
  6. * :: Number Numerical value
  7. * :: Boolean
  8. * :: Null Null
  9. * :: Undefined
  10. * :: Object objects
  11. *
  12. * where String Number Boolean Null Undefined is a basic data type
  13. * :: Whereas Object is a reference data type
  14. */
  15. /*
  16. * String
  17. * - strings need to be caused by quotes in JS
  18. * - Use either double or single quotes, but don't mix them up!
  19. * - quotes cannot be nested, double quotes cannot be put in double quotes, single quotes cannot be put in single quotes
  20. */
  21. var str = 'hello';
  22. str = 'I said: "What a beautiful day!"' ;
  1. /*
  2. We can use \ as an escape character in a string.
  3. You can use \ to escape when representing some special symbols.
  4. \" denotes "\"
  5. \' denotes '
  6. \n means change
  7. The \t tab - feels like a space.
  8. \\\ Indicates\
  9. * */
  10. str = "I said:\ "It's a beautiful day today\t! \"";
  11. // str = "\\\\\\";
  12. (str);

————————————————————————————————————————

  1. /*
  2. * All values in JS are of type Number.
  3. * :: Includes integers and floating point numbers (decimals)
  4. *
  5. * :: Maximum value of a number that can be expressed in JS
  6. * Number.MAX_VALUE
  7. * 1.7976931348623157e+308
  8. *
  9. * Number.MIN_VALUE Minimum value greater than 0
  10. * 5e-324
  11. *
  12. * If the number expressed using Number exceeds the maximum value, it returns a
  13. * Infinity denotes positive infinity
  14. * -Infinity means negative infinity
  15. * Checking Infinity with typeof also returns number
  16. * :: NaN is a special number that stands for Not A Number
  17. * Checking for a NaN using typeof also returns number
  18. */
  19. // Number 123
  1. // Number 123
  2. var a = 123;
  3. //String 123
  4. var b = "123";
  5. var result = typeof a;
  6. var result2 = typeof b;
  7. console.log(typeof result);
  8. console.log(typeof result2);
'
(of a computer) run

type The return value of this variable is the string representation of the type, which is a string.

Course Address: Liao Xuefeng j2ee Distributed Architect the first phase of the god course is here!
/youzhi/

That's something to figure out thoroughly!

And the return type is the lowercase form of the string, i.e. string number boolean null undefined object!!!!

 

  1. /*
  2. * :: Boolean
  3. * :: There are only two Boolean values, mainly used to make logical judgments
  4. * true
  5. * - indicates true
  6. * false
  7. * - indicates false
  8. *
  9. * :: Using typeof to check a boolean value returns boolean
  10. */
  11. var bool = false;
  12. (typeof bool);
  13. (bool);

 

  1. /*
  2. * :: The Null type has only one value, which is null
  3. * :: The value null is used exclusively to denote a null object
  4. * :: Using typeof to check for a null value returns object
  5. *
  6. * :: The Undefined type has only one value, undefind
  7. * :: When a variable is declared but not assigned a value, its value is undefined
  8. * Using typeof to check for an undefined also returns undefined
  9. */
  10. var a = null;
  11. var b = undefined;
  12. (typeof b);
  1. /*
  2. * :: Converting other data types to String
  3. * :: Modality I:
  4. * :: - Call the toString() method of the data type being converted
  5. * - this method does not affect the original variable, it returns the result of the conversion
  6. * - but note: there is no toString() method for the values null and undefined.
  7. * :: If their methods are called, an error is reported
  8. *
  9. * :: Modality II:
  10. * - call the String() function and pass the converted data as an argument to the function
  11. * - When using the String() function to do a forced type conversion, the
  12. * :: For Number and Boolean, it's actually a call to the toString() method.
  13. * :: But for null and undefined, the toString() method is not called
  14. * It converts null directly to "null".
  15. * Converts undefined directly to "undefined".
  16. *
  17. */
  18. var a = 123;
  19. // Call the toString() method of a
  20. // Calling xxx's yyyy() method is ()
  21. a = ();
  22. a = true;
  23. a = ();
  24. a = null;
  25. //a = (); //Error message
  26. a = undefined;
  27. //a = (); //Error message
  28. a = 123;
  29. // Call the String() function to convert a to a string.
  30. a = String(a);
  31. a = null;
  32. a = String(a);
  33. a = undefined;
  34. a = String(a);
  35. (typeof a);
  36. (a);

 

  1. /*
  2. * :: Converting other data types to Number
  3. * :: Conversion mode I:
  4. * :: Use of the Number() function
  5. * - strings --> numbers
  6. * :: 1. If it is a purely numeric string, it is converted directly to a number
  7. * :: 2. Convert to NaN if there are non-numeric elements in the string
  8. * :: 3. If the string is an empty string or a string with all spaces, it is converted to 0
  9. * - Boolean --> numbers
  10. * true to 1
  11. * false to 0
  12. *
  13. * - null --> number 0
  14. *
  15. * - undefined --> number NaN
  16. *
  17. * :: Conversion mode II:
  18. * - This approach is specifically used for strings
  19. * - parseInt() Converts a string to an integer.
  20. * - parseFloat() converts a string to a floating point number
  21. */
  22. var a = "123";
  23. // Call the Number() function to convert a to Number.
  24. a = Number(a);
  25. a = false;
  26. a = Number(a);
  27. a = null;
  28. a = Number(a);
  29. a = undefined;
  30. a = Number(a);
  31. a = "123567a567px";
  32. // call parseInt () function to convert a to Number
  33. /*
  34. * parseInt() removes valid integer content from a string.
  35. * :: Then converted to Number
  36. */
  37. a = parseInt(a);
  38. /*
  39. * :: parseFloat() is similar to parseInt(), except that it gets a valid decimal number.
  40. */
  41. a = "123.456.789px";
  42. a = parseFloat(a);
  43. /*
  44. * :: If parseInt() or parseFloat() is used for non-Strings
  45. * It will first convert it to a String and then manipulate the
  46. */
  47. a = true;
  48. a = parseInt(a);
  49. a = 198.23;
  50. a = parseInt(a);
  51. (typeof a);
  52. (a);

  1. /*
  2. * Operators are also called operators
  3. * :: Operators that allow one or more values to be manipulated and the results to be obtained
  4. * :: For example, typeof is an operator that can be used to obtain the type of a value.
  5. * It will return the type of the value as a string
  6. * number string boolean undefined object
  7. *
  8. * :: Arithmetic operators
  9. * When performing operations on values that are not of type Number, the values are converted to Number and then used in the operations.
  10. * Any operation with NaN yields NaN.
  11. *
  12. * +
  13. * + can perform an addition operation on two values and return the result
  14. * :: If addition is performed on two strings, a collocation is done
  15. * will concatenate the two strings into a single string and return
  16. * Any value that does addition with a string will be converted to a string first, and then it will do the string collocation with the string
  17. * -
  18. * - can perform subtraction on two values and return the result
  19. *
  20. * *
  21. * * Can multiply two values.
  22. * /
  23. * / can perform division on two values
  24. * %
  25. * :: % Modulo operation (taking a remainder)
  26. */
  1. var a = 123;
  2. var result = typeof a;
  3. //(typeof result);
  4. result = a + 1;
  5. result = 456 + 789;
  6. result = true + 1;
  7. result = true + false;
  8. result = 2 + null;
  9. result = 2 + NaN;
  10. result = "Hello" + "Big Handsome Guy";
  11. var str = "Hoeing," +
  12. "Sweat the sweat of the brow," +
  13. "Who knows what's on the plate," +
  14. "Grain for Grain".
  15. result = 123 + "1";
  16. result = true + "hello";
  17. // Any value added to a string is converted to a string and a collocation is done.
  18. /*
  19. * :: We can use this feature to convert an arbitrary data type to String
  20. * We just need to add a "" to any datatype to convert it to a String.
  21. * :: This is an implicit type conversion, done automatically by the browser, which actually calls the String() function as well
  22. */
  23. var c = 123;
  24. c = c + "";
  25. //c = null;
  26. //c = c + "";
  27. //(result);
  28. //(typeof c);
  29. //("c = "+c);
  30. result = 1 + 2 + "3"; //33
  31. result = "1" + 2 + 3; //123
  32. result = 100 - 5;
  33. result = 100 - true;
  34. result = 100 - "1";
  35. result = 2 * 2;
  36. result = 2 * "8";
  37. result = 2 * undefined;
  38. result = 2 * null;
  39. result = 4 / 2;
  40. result = 3 / 2;
  41. /*
  42. * Any value that does the - * / operation is automatically converted to Number.
  43. * :: We can use this feature to do implicit type conversions
  44. * :: It can be converted to Number by providing a value of -0 *1 /1.
  45. * :: The principle is the same as the Number() function, which is simpler to use
  46. */
  47. var d = "123";
  48. //("result = "+result);
  49. d = d - 0;
  50. /*(typeof d);
  51. (d);*/
  52. result = 9 % 3;
  53. result = 9 % 4;
  54. result = 9 % 5;
  55. ("result = "+result);
  56. </script>

 

  1. var a = null;
  2. var a= undefined;
  3. (+a);
  4. /**
  5. * + a
  6. *
  7. * If a is not a numeric type, first convert a to a numeric type, then go to the budget, so you can use
  8. * +a Hermit converts to a numeric type!
  9. */
  1. /*
  2. * :: Unary operators, which require only one operand
  3. * + positive sign
  4. * - the plus sign does not have any effect on the numbers
  5. * - negative sign
  6. * - Negative sign can invert the negative sign on a number
  7. *
  8. * - for values not of type Number.
  9. * It will be converted to Number first, and then in the operation
  10. * :: It is possible to use +, on a different datatype, to convert it to a number.
  11. * :: It works like the Number() function.
  12. */