Javascript初学者非常有用的24个小技巧

Vba调用JS计算24节气 Private Sub CommandButton1_Click() ' Vba调用JS计算24节气 tt = "2013" With CreateObject("Msxml2.XMLHTTP.5.0") .Open "GET", "http://www.fjptsz.com/xxjs/xjw/rj/113.htm", False .send 阅读详情

    注:是从别的地方转来的。是英文。我就不翻译了。看不懂的硬着头皮看吧,总有能看懂的时候。

    24 JavaScript Best Practices for Beginners

    1. Use === Instead of ==
    JavaScript utilizes two different kinds of equality operators: === | !== and == | != It is considered best practice to always use the former set when comparing.

    "If two operands are of the same type and value, then === produces true and !== produces false." - JavaScript: The Good Parts

    However, when working with == and !=, you'll run into issues when working with different types. In these cases, they'll try to coerce the values, unsuccessfully.

    2. Eval = Bad
    For those unfamiliar, the "eval" function gives us access to JavaScript's compiler. Essentially, we can execute a string's result by passing it as a parameter of "eval".

    Not only will this decrease your script's performance substantially, but it also poses a huge security risk because it grants far too much power to the passed in text. Avoid it!

    3. Don't Use Short-Hand
    Technically, you can get away with omitting most curly braces and semi-colons. Most browsers will correctly interpret the following:

    view plaincopy to clipboardprint?
    if(someVariableExists)
       x = false

    if(someVariableExists)
       x = false
    However, consider this:

    view plaincopy to clipboardprint?
    if(someVariableExists)
       x = false
       anotherFunctionCall();

    if(someVariableExists)
       x = false
       anotherFunctionCall();
    One might think that the code above would be equivalent to:

    view plaincopy to clipboardprint?
    if(someVariableExists) {
       x = false;
       anotherFunctionCall();
    }

    if(someVariableExists) {
       x = false;
       anotherFunctionCall();
    }
    Unfortunately, he'd be wrong. In reality, it means:

    view plaincopy to clipboardprint?
    if(someVariableExists) {
       x = false;
    }
    anotherFunctionCall();

    if(someVariableExists) {
       x = false;
    }
    anotherFunctionCall();
    As you'll notice, the indentation mimics the functionality of the curly brace. Needless to say, this is a terrible practice that should be avoided at all costs. The only time that curly braces should be omitted is with one-liners, and even this is a highly debated topic.

    view plaincopy to clipboardprint?
    if(2 + 2 === 4) return 'nicely done';

    if(2 + 2 === 4) return 'nicely done';
    Always Consider the Future
    What if, at a later date, you need to add more commands to this if statement. In order to do so, you would need to rewrite this block of code. Bottom line - tread with caution when omitting.

    4. Utilize JS Lint
    JSLint is a debugger written by Douglas Crockford. Simply paste in your script, and it'll quickly scan for any noticeable issues and errors in your code.

    "JSLint takes a JavaScript source and scans it. If it finds a problem, it returns a message describing the problem and an approximate location within the source. The problem is not necessarily a syntax error, although it often is. JSLint looks at some style conventions as well as structural problems. It does not prove that your program is correct. It just provides another set of eyes to help spot problems."
    - JSLint Documentation

    Before signing off on a script, run it through JSLint just to be sure that you haven't made any mindless mistakes.

    5. Place Scripts at the Bottom of Your Page
    This tip has already been recommended in the previous article in this series. As it's highly appropriate though, I'll paste in the information.


    Remember -- the primary goal is to make the page load as quickly as possible for the user. When loading a script, the browser can't continue on until the entire file has been loaded. Thus, the user will have to wait longer before noticing any progress.

    If you have JS files whose only purpose is to add functionality -- for example, after a button is clicked -- go ahead and place those files at the bottom, just before the closing body tag. This is absolutely a best practice.

    Better
    view plaincopy to clipboardprint?
    <p>And now you know my favorite kinds of corn. </p>
    <script type="text/javascript" src="path/to/file.js"></script>
    <script type="text/javascript" src="path/to/anotherFile.js"></script>
    </body>
    </html>

    <p>And now you know my favorite kinds of corn. </p>
    <script type="text/javascript" src="path/to/file.js"></script>
    <script type="text/javascript" src="path/to/anotherFile.js"></script>
    </body>
    </html>
    6. Declare Variables Outside of the For Statement
    When executing lengthy "for" statements, don't make the engine work any harder than it must. For example:

    Bad
    view plaincopy to clipboardprint?
    for(var i = 0; i < someArray.length; i++) {
       var container = document.getElementById('container');
       container.innerHtml += 'my number: ' + i;
       console.log(i);
    }

    for(var i = 0; i < someArray.length; i++) {
       var container = document.getElementById('container');
       container.innerHtml += 'my number: ' + i;
       console.log(i);
    }
    Notice how we must determine the length of the array for each iteration, and how we traverse the dom to find the "container" element each time -- highly inefficient!

    Better
    view plaincopy to clipboardprint?
    var container = document.getElementById('container');
    for(var i = 0, len = someArray.length; i < len;  i++) {
       container.innerHtml += 'my number: ' + i;
       console.log(i);
    }

    var container = document.getElementById('container');
    for(var i = 0, len = someArray.length; i < len;  i++) {
       container.innerHtml += 'my number: ' + i;
       console.log(i);
    }
    Bonus points to the person who leaves a comment showing us how we can further improve the code block above.

    7. The Fastest Way to Build a String
    Don't always reach for your handy-dandy "for" statement when you need to loop through an array or object. Be creative and find the quickest solution for the job at hand.

    view plaincopy to clipboardprint?
    var arr = ['item 1', 'item 2', 'item 3', ...];
    var list = '<ul><li>' + arr.join('</li><li>') + '</li></ul>';

    var arr = ['item 1', 'item 2', 'item 3', ...];
    var list = '<ul><li>' + arr.join('</li><li>') + '</li></ul>';
    I won’t bore you with benchmarks; you’ll just have to believe me (or test for yourself) - this is by far the fastest method!

    Using native methods (like join()), regardless of what’s going on behind the abstraction layer, is usually much faster than any non-native alternative.
    - James Padolsey, james.padolsey.com

    8. Reduce Globals
    "By reducing your global footprint to a single name, you significantly reduce the chance of bad interactions with other applications, widgets, or libraries."
    - Douglas Crockford

    view plaincopy to clipboardprint?
    var name = 'Jeffrey';
    var lastName = 'Way';

    function doSomething() {...}

    console.log(name); // Jeffrey -- or window.name

    var name = 'Jeffrey';
    var lastName = 'Way';

    function doSomething() {...}

    console.log(name); // Jeffrey -- or window.name
    Better
    view plaincopy to clipboardprint?
    var DudeNameSpace = {
       name : 'Jeffrey',
       lastName : 'Way',
       doSomething : function() {...}
    }
    console.log(DudeNameSpace.name); // Jeffrey

    var DudeNameSpace = {
       name : 'Jeffrey',
       lastName : 'Way',
       doSomething : function() {...}
    }
    console.log(DudeNameSpace.name); // Jeffrey
    Notice how we've "reduced our footprint" to just the ridiculously named "DudeNameSpace" object.

    9. Comment Your Code
    It might seem unnecessary at first, but trust me, you WANT to comment your code as best as possible. What happens when you return to the project months later, only to find that you can't easily remember what your line of thinking was. Or, what if one of your colleagues needs to revise your code? Always, always comment important sections of your code.

    view plaincopy to clipboardprint?
    // Cycle through array and echo out each name.
    for(var i = 0, len = array.length; i < len; i++) {
       console.log(array[i]);
    }

    // Cycle through array and echo out each name.
    for(var i = 0, len = array.length; i < len; i++) {
       console.log(array[i]);
    }
    10. Embrace Progressive Enhancement
    Always compensate for when JavaScript is disabled. It might be tempting to think, "The majority of my viewers have JavaScript enabled, so I won't worry about it." However, this would be a huge mistake.

    Have you taken a moment to view your beautiful slider with JavaScript turned off? (Download the Web Developer Toolbar for an easy way to do so.) It might break your site completely. As a rule of thumb, design your site assuming that JavaScript will be disabled. Then, once you've done so, begin to progressively enhance your layout!

    11. Don't Pass a String to "SetInterval" or "SetTimeOut"
    Consider the following code:

    view plaincopy to clipboardprint?
    setInterval(
    "document.getElementById('container').innerHTML += 'My new number: ' + i", 3000
    );

    setInterval(
    "document.getElementById('container').innerHTML += 'My new number: ' + i", 3000
    );
    Not only is this code inefficient, but it also functions in the same way as the "eval" function would. Never pass a string to SetInterval and SetTimeOut. Instead, pass a function name.

    setInterval(someFunction, 3000);

    setInterval(someFunction, 3000);
    12. Don't Use the "With" Statement
    At first glance, "With" statements seem like a smart idea. The basic concept is that they can be used to provide a shorthand for accessing deeply nested objects. For example...

    view plaincopy to clipboardprint?
    with (being.person.man.bodyparts) {
       arms = true;
       legs = true;
    }

    with (being.person.man.bodyparts) {
       arms = true;
       legs = true;
    }
    -- instead of --

    view plaincopy to clipboardprint?
    being.person.man.bodyparts.arms = true;
    being.person.man.bodyparts.legs= true;

    being.person.man.bodyparts.arms = true;
    being.person.man.bodyparts.legs= true;
    Unfortunately, after some testing, it was found that they "behave very badly when setting new members." Instead, you should use var.

    view plaincopy to clipboardprint?
    var o = being.person.man.bodyparts;
    o.arms = true;
    o.legs = true;

    var o = being.person.man.bodyparts;
    o.arms = true;
    o.legs = true;
    13. Use {} Instead of New Object()
    There are multiple ways to create objects in JavaScript. Perhaps the more traditional method is to use the "new" constructor, like so:

    view plaincopy to clipboardprint?
    var o = new Object();
    o.name = 'Jeffrey';
    o.lastName = 'Way';
    o.someFunction = function() {
       console.log(this.name);
    }

    var o = new Object();
    o.name = 'Jeffrey';
    o.lastName = 'Way';
    o.someFunction = function() {
       console.log(this.name);
    }
    However, this method receives the "bad practice" stamp without actually being so. Instead, I recommend that you use the much more robust object literal method.

    Better
    view plaincopy to clipboardprint?
    var o = {
       name: 'Jeffrey',
       lastName = 'Way',
       someFunction : function() {
          console.log(this.name);
       }
    };

    var o = {
       name: 'Jeffrey',
       lastName = 'Way',
       someFunction : function() {
          console.log(this.name);
       }
    };
    Note that if you simply want to create an empty object, {} will do the trick.

    view plaincopy to clipboardprint?
    var o = {};

    var o = {};
    "Objects literals enable us to write code that supports lots of features yet still make it a relatively straightforward for the implementers of our code. No need to invoke constructors directly or maintain the correct order of arguments passed to functions, etc." - dyn-web.com

    14. Use [] Instead of New Array()
    The same applies for creating a new array.

    Okay
    view plaincopy to clipboardprint?
    var a = new Array();
    a[0] = "Joe";
    a[1] = 'Plumber';

    var a = new Array();
    a[0] = "Joe";
    a[1] = 'Plumber';
    Better
    view plaincopy to clipboardprint?
    var a = ['Joe','Plumber'];

    var a = ['Joe','Plumber'];
    "A common error in JavaScript programs is to use an object when an array is required or an array when an object is required. The rule is simple: when the property names are small sequential integers, you should use an array. Otherwise, use an object." - Douglas Crockford

    15. Long List of Variables? Omit the "Var" Keyword and Use Commas Instead
    view plaincopy to clipboardprint?
    var someItem = 'some string';
    var anotherItem = 'another string';
    var oneMoreItem = 'one more string';

    var someItem = 'some string';
    var anotherItem = 'another string';
    var oneMoreItem = 'one more string';
    Better
    view plaincopy to clipboardprint?
    var someItem = 'some string',
        anotherItem = 'another string',
        oneMoreItem = 'one more string';

    var someItem = 'some string',
        anotherItem = 'another string',
        oneMoreItem = 'one more string';
    ...Should be rather self-explanatory. I doubt there's any real speed improvements here, but it cleans up your code a bit.

    17. Always, Always Use Semicolons
    Technically, most browsers will allow you to get away with omitting semi-colons.

    view plaincopy to clipboardprint?
    var someItem = 'some string'
    function doSomething() {
      return 'something'
    }

    var someItem = 'some string'
    function doSomething() {
      return 'something'
    }
    Having said that, this is a very bad practice that can potentially lead to much bigger, and harder to find, issues.

    Better
    view plaincopy to clipboardprint?
    var someItem = 'some string';
    function doSomething() {
      return 'something';
    }

    var someItem = 'some string';
    function doSomething() {
      return 'something';
    }
    18. "For in" Statements
    When looping through items in an object, you might find that you'll also retrieve method functions as well. In order to work around this, always wrap your code in an if statement which filters the information

    view plaincopy to clipboardprint?
    for(key in object) {
       if(object.hasOwnProperty(key) {
          ...then do something...
       }
    }

    for(key in object) {
       if(object.hasOwnProperty(key) {
          ...then do something...
       }
    }
    As referenced from JavaScript: The Good Parts, by Douglas Crockford.

    19. Use Firebug's "Timer" Feature to Optimize Your Code
    Need a quick and easy way to determine how long an operation takes? Use Firebug's "timer" feature to log the results.

    view plaincopy to clipboardprint?
    function TimeTracker(){
     console.time("MyTimer");
     for(x=5000; x > 0; x--){}
     console.timeEnd("MyTimer");
    }

    function TimeTracker(){
     console.time("MyTimer");
     for(x=5000; x > 0; x--){}
     console.timeEnd("MyTimer");
    }
    20. Read, Read, Read...
    While I'm a huge fan of web development blogs (like this one!), there really isn't a substitute for a book when grabbing some lunch, or just before you go to bed. Always keep a web development book on your bedside table. Here are some of my JavaScript favorites.

    Object-Oriented JavaScript
    JavaScript: The Good Parts
    Learning jQuery 1.3
    Learning JavaScript
    Read them...multiple times. I still do!

    21. Self-Executing Functions
    Rather than calling a function, it's quite simple to make a function run automatically when a page loads, or a parent function is called. Simply wrap your function in parenthesis, and then append an additional set, which essentially calls the function.

    view plaincopy to clipboardprint?
    (function doSomething() {
       return {
          name: 'jeff',
          lastName: 'way'
       };
    })();

    (function doSomething() {
       return {
          name: 'jeff',
          lastName: 'way'
       };
    })();
    22. Raw JavaScript Can Always Be Quicker Than Using a Library
    JavaScript libraries, such as jQuery and Mootools, can save you an enormous amount of time when coding -- especially with AJAX operations. Having said that, always keep in mind that a library can never be as fast as raw JavaScript (assuming you code correctly).

    jQuery's "each" method is great for looping, but using a native "for" statement will always be an ounce quicker.

    23. Crockford's JSON.Parse
    Although JavaScript 2 should have a built-in JSON parser, as of this writing, we still need to implement our own. Douglas Crockford, the creator of JSON, has already created a parser that you can use. It can be downloaded HERE.

    Simply by importing the script, you'll gain access to a new JSON global object, which can then be used to parse your .json file.

    view plaincopy to clipboardprint?
    var response = JSON.parse(xhr.responseText);

    var container = document.getElementById('container');
    for(var i = 0, len = response.length; i < len; i++) {
      container.innerHTML += '<LI>' + response[i].name + ' : ' + response[i].email + '';
    }
    /LI>

     var response = JSON.parse(xhr.responseText);

     var container = document.getElementById('container');
     for(var i = 0, len = response.length; i < len; i++) {
       container.innerHTML += '' + response[i].name + ' : ' + response[i].email + '';
     }
    24. Remove "Language"
    Years ago, it wasn't uncommon to find the "language" attribute within script tags.

    view plaincopy to clipboardprint?
    <script type="text/javascript" language="javascript">
    ...
    </script>

    <script type="text/javascript" language="javascript">
    ...
    </script>
    However, this attribute has long since been deprecated; so leave it out.

    That's All, Folks
    So there you have it; twenty-four essential tips for beginning JavaScripters. Let me know your quick tips! Thanks for reading. What subject should the third part in this series cover?

    Follow us on Twitter, or subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.

JavaScript入门教程(初学者不可多得的优秀入门教材-通俗易懂-专业术语通俗化)(1) 立即下载

相关推荐

HFSS入门 - 传输线线路损耗和串扰仿真

下图中两相近传输线存在端口间的串扰,而同一根传输线存在线路损耗。 我们可用S21描述端口1到端口2的线路损耗(插损?),用S13描述近端串扰,S24描述远端串扰,串扰通常要求-20dB以下。 实验目的:传输线线路损耗和串扰仿真 具体步骤: 1.草图: 其中板厚Subh为1mm。其余参数具体值如下: 2.由草图作图: 其中介质板表面设为GND。 3.设置激励:先在第一根传输线相连的XZ平面上做一...

qq_37274411的博客 9177

JavaScript学习笔记(一)

1、引入JavaSciprt 1、内部标签 <script> alert('hello,world'); </script> 2、外部引用 test.html <script src="zy.js"></script> zy.js alert('hello,world'); 2、基本语法入门 <!DOCTYPE html> <html lang="en"> <head> <meta chars

柒柒柒柒 238

【OpenCV3】cv::compare()使用详解

cv::compare()主要用于两个图像之间进行逐像素的比较,并输出比较的结果。具体用法如下: cv::compare() bool cv::compare( cv::InputArray src1, // 输入数组1 cv::InputArray src2, // 输入数组2 cv::OutputArray dst, // 输出数组 int cmpop // 比较操作子,见下表 ...

guduruyu的专栏 9771

JavaScript基础,新手详细入门

学习JavaScript笔记,巩固

wushengkuang的博客 1661

解决 python2.7中 ImportError: No module named Crypto.Signature

我的解决办法,先查看有没有安装 pip,直接执行pip 回车 没有出现null什么的就安装了,如果没有安装去其他博客哪里看一下,正常情况是默认就有的,然后使用。发现我自己也不会啊,就百度看看,想着网上的解决方法一大片,但是都是废话,能用的没有几个,而且能安装的没有几个。这个里面的python2、3就是系统里面的python版本,直接跟我这样就可以了除非版本不一样,也就是没有这个版本。就可以使用了,第一个应该是卸载之前的,然后重新安装,我的就是这样解决的。就比如我的,我现在使用的 python2.7。

记录一下 1613

VTK基础教程(1)- vtkPolyData 介绍

目录 VTK的编译与环境搭建 VTK一般渲染流程 VTK数据类型-vtkPolyData 使用vtk自带的多边形数据 使用自己创建的数据 添加顶点颜色 添加面颜色 VTK的编译与环境搭建 这部分目前已经有了大佬做了成熟的傻瓜式配置,大家可以参考这篇文章:VTK+VS2019(或其他版本均可) 傻瓜式一站式 配置_Nancy_fairy的博客-CSDN博客_vs2019 vtk VTK一般渲染流程 这部分的介绍也很多,大家可以参考这篇文章:VTK笔记-了解VTK_黑山老妖的博客.

qq_35769071的博客 9062

零基础小白如何自学JavaScript(JS)

通过从基础到进阶的学习,你将掌握更多的工具和技巧,能够构建更加复杂和高效的Web应用。参与开源项目不仅能帮助你积累实际经验,还能提高你的编程能力。在掌握了基础的JavaScript后,你可以深入学习一些更高级的概念,这些概念会让你在编写更高效和复杂的代码时更加得心应手。当你掌握了JavaScript的高级特性后,可以开始接触一些前端开发的现代工具和框架,这将帮助你构建更复杂和高效的应用。当你对JavaScript有了较好的掌握之后,可以进一步学习一些前端框架和工具,它们可以帮助你构建更复杂和高效的应用。

小宝哥Code的专栏 2120

【个人学习总结】CRC校验原理及实现

CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定。循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将得到的结果附在帧的后面,接收设备也执行类似的算法,以保证数据传输的正确性和完整性。 ..................

星Yeah 的博客 7974

javascript基础入门菜鸟,javascript基础入门教程

object 对象。

阿发狗伪原创 887

对CryptoDriver里密钥格式定义的探索(1)

一入网络安全才发现深似海,传统汽车MCU码农转型之路异常艰难。在CP AUTOSAR中的CryptoDriver SWS对密钥格式的需求来源于RFC,其中要求了RSA、ECC、SHE等key material的格式。再往下看,我就有些迷糊了,例如关于RSA Private Key的OCTEE STRING格式根据IETF RFC8017,Public Key又得根据RFC5280,完全不得其解。所以今天先从生成密钥对,并对其进行解析开始,一步一步拆解。

认真搞搞汽车MCU 534

AI安全护栏评测:TrustedExecBench如何量化评估大模型防护能力

在人工智能和机器学习领域,模型安全对齐是确保AI系统可靠、可控的核心技术。其原理是通过设计安全机制(即“护栏”)来约束模型行为,防止生成有害、偏见或越界内容。这项技术的核心价值在于平衡AI能力与风险管控,是可信AI部署的基石。应用场景广泛覆盖内容审核、对话系统、代码生成等需要人机交互的领域。本文聚焦的TrustedExecBench项目,正是针对“护栏”性能量化评估这一痛点,提供了一个标准化、自动化的开源评测框架。该工具通过构建多维度的恶意测试套件,并引入基于模型的动态评判机制,能够系统性地检验大语言模型在

weixin_42525428的博客 382

JavaScript入门

JavaScript入门秘籍,欲练此功,关注有功

微风洋洋的博客 1万+

【华为OD机试真题】458、堆内存申请 | 机试真题+思路参考+代码解析(CD卷)(C++、Java、Py)

题目描述 >有一个总空间为100字节的堆,现要从中新申请一块内存,内存分配原则为优先紧接着前一块已使用内存分配空间足够且最接近申请大小的空闲内存。

KJ.JK 1万+

【JavaScript】JavaScript初学者福利!必须收藏的24条小技巧

这篇文章将回顾JavaScript的知识 !如果你看完了下面的内容,请务必让我们知道你掌握的小技巧! 1.使用 === 代替 == JavaScript 使用2种不同的等值运算符:===|!== 和 ==|!=,在比较操作中使用前者是最佳实践。“如果两边的操作数具有相同的类型和值,===返回true,!==返回false。”——《JavaScript:语言精粹》然而,当使用==和!=时,你

DOTAxiaojian的专栏 948

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

JavaScript初学者福利!必须收藏的24条小技巧

JavaScript初学者福利!必须收藏的24条小技巧 前端小编发布于 2013-12-15 22:52 查看数: 2343 评论数: 6 帖子模式 这篇文章将回顾JavaScript的知识 !如果你看完了下面的内容,请务必让我们知道你掌握的小技巧!1.使用 === 代替 ==JavaScript 使用2种不同的等值运算符:===|!==...

weixin_30727835的博客 75

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

24个适合初学者练习的CSS 和 Javascript 动画效果案例

英文 | https://niemvuilaptrinh.medium.com/24-css-javascript-animation-effects-a4c5b6e98a59翻译 | 杨...

web前端开发 8054

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

给JavaScript初学者的24条最佳实践

转自:颜海镜 专注web前端,分享html,css,javascript,jquery等相关原创知识…… 给JavaScript初学者的24条最佳实践 作为“30 HTML和CSS最佳实践”的后续,本周,我们将回顾JavaScript的知识 !如果你看完了下面的内容,请务必让我们知道你掌握的小技巧! 1.使用 === 代替 == JavaScript 使用2种不同的等值运算符:===|...

LeeCSDN77的博客 266

javascript小技巧-js小技巧收集

每一项都是js中的小技巧,但十分的实用! 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document) 5.得到表单中元素的名称和值:document.ge

wocan的专栏 1550

JS小技巧

js小技巧每一项都是js中的小技巧,但十分的实用! 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document) 5.得到表单中元素的名称和值:docume

小兵的专栏 4638

JavaScript 初学者应知的 24 条最佳实践

原文:24 JavaScript Best Practices for Beginners (注:阅读原文的时候没有注意发布日期,觉得不错就翻译了,翻译到 JSON.parse 那一节觉得有点不对路才发现是 2009 年发布的文章,不过还是不错的啦。另外,文章虽说 24 条最佳实践,其实只有 23 条,不知道原作者怎么漏了一条。) 1. 优先使用 ===,而不是 == JavaScript

justjavac(迷渡) 2002

[转]初学者JavaScript 小技巧总结

javascript小技巧-js小技巧收集  每一项都是js中的小技巧,但十分的实用! 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,docu

又是再见? 1221

JavaScript初学者应知的24条最佳实践(译)

1.优先使用===,而不是== JavaScript使用两种相等性操作符:===|!==和==|!=。通常认为做比较的最佳实践是使用前一组操作符。 “若两个操作数的类型和值相同,那么===比较的结果为真,!==比较的结果为假。” — JavaScript语言精粹(JavaScript: The Good Parts) 然而,如果使用==和!=,当比较不同类型的操作数时,你就会碰到问题啦。在这种情况下,这组操作符会尝试对操作数的值做无用的强制转换。

.NET快速开发框架 2721
上一篇: 让 FCKeditor 支持多用户Web环境(以PHP为例)
下一篇: CSDN 西安俱乐部,吸收西安学生会员
zhangking
博客等级 码龄25年 2706粉丝 495原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值