Article From:https://www.cnblogs.com/coffees/p/9967686.html

JavaScriptAs a scripting language belonging to the network, it has been widely used in the development of Web applications. It is often used to add various dynamic functions to web pages to provide users with more smooth and beautiful browsing effect. Usually JavaScript scripts implement their functions by embedding them in HTML. Next,For you a brief introduction to the JavaScript learning guide.

Picture 1

  Setting defer attributes to script elements allows browsers to process page parts in advance, and then process script parts at the end of page processing and ready for display, which can improve the speed of page loading.

  <script defer=”defer”>

  //content

  </script>

  Placing script elements in the head element can improve the maintainability of the web page, and placing script elements at the end of the body element can improve the loading speed of the page. Either way, you must ensure consistency of script locations or put them all in the head element.Or it’s all at the end of the body element.

  Variables are defined with the keyword VaR and are local variables. If VaR is not used, then variables are global variables and can be accessed inside and outside functions. It is generally not recommended to set global variables, because it is easy to cause data loss.

  It is best to provide alternatives for users who do not support or open JS, with the help of noscript elements. If the browser supports JS, it ignores the content in noscript, and if it does not support JS, it chooses noscript.Content.

  <script>

  function sayHello() {

  document.writeln(“Hello JS”);

  }

  </script>

  <noscript>

  <p>Hello JS</p>

  </noscript>

  Using toString () method, decimal integers can be changed to octal or hexadecimal.

  var intNumber = 16;

  var octNumber = intNumber.toString(8);

  var hexNumber = intNumber.toString(16);

  To reduce JS code, we can use some online compression tools, such as Packer.

  == Operators automatically convert the data types of variables, and then determine whether the values of the same data types are equal. ==== is a more stringent judgment of the same kind, returning true only if the operands have the same value and type. The difference between!= and!== is the same.

  Array Objects have four ways to maintain queues and lists: push, pop, shift, unshift. The push method adds elements to the end of an array, the unshift method adds elements to the beginning of an array, and the pop method removes arrays.The last element, the shift method, removes the first element.

Leave a Reply

Your email address will not be published. Required fields are marked *