Learn Javascript Visually 读书笔记

You Don't Know JS Yet (book series) - 2nd Edition by Kyle Simpson You Don’t Know JS Yet (book series) - 2nd Edition 全文阅读地址From https://github.com/getify/You-Dont-Know-JS 我的GitHub文件: https://github.com/Li-YangZhong/Kyle_Simpson_You_Don-t_Know_JS_Yet_-Get_Started.git... 阅读详情

Imperative programming  

In computer science, imperative programming, as opposed to declarative programming, is a programming paradigm that describes computation in terms of a program state and statements that change the program state. In much the same way as the imperative mood in natural languages expresses commands to take action, imperative programs are a sequence of commands for the computer to perform.

imperative programming  

命令式程度设计


jQuery, Dojo and others are used to extend JavaScript and increase its potential and usefulness. They are libraries of code available for you to simplify some of the more complex commonly used code. After all, JavaScript is very powerful and fast, but writing everything from scratch can be very tedious.


<script type="text/javascript"> alert("It’s best if I sit low.");</script> <!--embed script; 双引号不能用中文输入状态下的双引号-->

JavaScript can be interpreted or compiled. Most modern browsers compile the code before execution.

When you have statements in one line, the first semicolon is required. When you have statements separated by line breaks, semicolons are optional as the line break acts as one.

The brackets hold arrays, braces create object group statements, while parentheses supply parameters, group expressions, and execute functions.

JavaScript also has DYNAMIC TYPES. This means that the same variable can be used as more than one type.

Variable names can start with a letter, underscore or the dollar sign "$".

Declaration is reserving a space in a memory.


The most common unary operators are:a++ , a--; which take the value and then add/subtract 1 to it and assigns it back to the variable. Similar to a = a + 1; or a = a – 1;

++a, --a; which adds/subtract 1 then take the value.


Print out a string and the value of a variable:

var a = 10;

a++;

console.log("The value of a is: " + a);

Or

var a = 10;

a++;

console.log("The value of a is: ", a);

 JavaScript does not have block scope.

Expressions are sets of literals, variables and operators that resolve to a value. So if the line of code gives you a value, then it is an expression. There are two types of expressions: those that assign a value to a variable and those that simply have a value.


Form feed is a page-breaking ASCII control character. It forces the printer to eject the current page and to continue printing at the top of another. Often, it will also cause a carriage return. 


For loop:

for (i = 0; i < 5; ++i) {

console.log( "The number is " + i);

}

For in loop:

 

var person = {fname:"John", lname:"Doe", age:25};

var text = "";

var x;

for (x in person) {

text += person[x];

}

console.log(text);        

While loop:

var i = 0;                        

while (i < 10) {

console.log("The number is " + i);

i++;

}

Do while loop:

var i = 0;

do {

    console.log("The number is " + i);
    i++;
}

while (i < 10);

When checking source code, you can usually identify arrays in JavaScript because the name is often a plural, like colors instead of color, and so on. This is due to the fact that arrays are a list of things.

//using array

var num = [1,2,3,4,5];

num[0] = "Mike"; //change the first element

num[4] = ["red", "blue", "green"]; //change the last element

alert(num);
//remove the last element of an array

var colors = ["Blue", "Red", "Orange"];

colors.pop();

alert(colors);
//adding an element to the end of an array

var colors = ["Blue", "Red", "Orange"];

colors.push("Yellow");

alert(colors);
//remove the first element of an array

var colors = ["Blue", "Red", "Orange"];

colors.shift();

alert(colors);
//adding an element to the beginning of an array

var colors = ["Blue", "Red", "Orange"];

colors.unshift("Green");

alert(colors);
//sorting an array of strings

var colors = ["Blue", "Red", "Orange"];

alert(colors.sort());
//sorting an array of numbers

var scores = [3, 95, 90, 50, 20, 10];

alert(scores.sort());//this will sort numbers based on their left most number.

alert(scores.sort(function(a, b){return a-b}));//this will sort numbers from small to big

alert(scores.sort(function(a, b){return a-b}).reverse());//reverse an array
//create an empty array

var result = [];
//create the numbers 11 to 23 included

for (var num = 11;num <=23; num++) {

    //add the number to the end of the array every time you run the loop

    result.push(num);

}

//display the content of the array

alert(result);        

//function

var x = myFunction(4, 3); // Function is called, the return value will end up in x

function myFunction(a, b) {

return a + b; // Function returns the product of a and b

}

alert(x);

alert("Sum of 4 and 3 is: "+myFunction(3,4));

//convert centimeter to inch                        

function cm2in(x) {

    var convert = x/2.54;

    return Math.round(convert) + '"';

}

alert(cm2in(16));
//nesting a function inside another function

function foo(a, b) {

    function bar() {
        return a + b;
    }


return bar();

}


var result = foo(1, 2);

console.log(result);

//计算直角三角形的斜边长度

function hypotenuse(a, b) {

function square(x) { return x*x; }

return Math.sqrt(square(a) + square(b)); // sqrt() is a function from the math library

}


var hypotenuse_length = hypotenuse(3,4);

console.log(hypotenuse_length);

JavaScript can change all the HTML elements, attributes, and CSS styles on the page.

Javascript code should be put after the HTML elements that it wants to manipulate.

<script type="text/javascript"> 

function count_h2(){ 

var total_h2=document.getElementsByTagName("h2"); 

alert("total h2 tags are: "+total_h2.length); 

}

</script>


<button onclick="count_h2()">count h2 elements</button>

//function can be called before being declared.

console.log(foo());

function foo() { return 8; }

Function statement is where a statement begins with the word “function”. If not, it’s a function expression.

function functionName(parameters) {

    //code to be executed

}
console.log(Math.pow(2,10));

//raise the number 2 to the power of 10

function power(x) {

var raise= x * x * x * x * x * x * x * x * x * x; // (x10)

return raise;

}

console.log(power(2));//1026
/* In function expression, function name can be omitted in a function expression to create an anonymous function.*/

var variableName = function(parameters) {

    //code to be executed

};

// if you want to refer to the current function inside the function body, then you need to create a named function expression. The name will be local only to the function body.

//Immediately-invoked function expressions.

( function () {

console.log("no need to call me again");

}() );

//The second pair of parentheses at the end invokes the function
//Immediately-invoked function expressions.


var x = function() {

    console.log("no need to call me again");

}();

//The second pair of parentheses at the end calls and closes the function

//if we try to call it later, we get an error:

//x();

//TypeError: x is not a function

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

(function () {
    statements
})();

It is a design pattern which is also known as a Self-Executing Anonymous Function and contains two major parts. The first is the anonymous function with lexical scope enclosed within the Grouping Operator (). This prevents accessing variables within the IIFE idiom as well as polluting the global scope.

The second part creates the immediately executing function expression () through which the JavaScript engine will directly interpret the function.

With wrapping the anonymous function inside the parentheses, the JavaScript parses knows to treat it as a function expression and not as a function declaration. If it is treated as a function declaration, then we will need a name for the function to avoid syntax errors, and it will also need to be invoked at some point.

Since the function in our IIFE is a function expression and it is not being assigned to a global variable, no global properties are being created, and thus, all the properties are created locally, so we get local scope.

(function () {

    var aName = "Barry";

console.log(aName);

})();

// Variable name is not accessible from the outside scope

aName // throws "Uncaught ReferenceError: aName is not defined"

// Assigning the IIFE to a variable stores the function's return value, not the function definition itself.

var result = (function () {

    var name = "Barry";

    return name;

})();

// Immediately creates the output:

console.log(result); // "Barry"

JavaScript has function-level scope. The variables inside a function are invisible to the outside. The local scope can “see” the global scope, but the global scope can’t “see” the local scope.

In JavaScript, scope is the set of variables, objects, and functions that you have access to.

Furthermore, objects and functions are also variables in JavaScript.

When you assign a value to a variable that has not been declared, it will automatically become global.

Hoisting is when function and variable declarations are moved to the top of their scope. This is the default behavior of JavaScript.

In JavaScript, a variable can be used before it has been declared.

x = 5; // Assign 5 to x

elem = document.getElementById("demo"); // Find an element

elem.innerHTML = x; // Display x in the element

var x; // Declare x
//When you assign a value to a variable that has not been declared, it will automatically become global.

function countApples() {
    sim= 4;
    console.log(sim);
}

var sim;

countApples(sim);//output 4

Since not many developers are familiar with hoisting in JavaScript, it is recommended to declare all variables at the beginning of every scope.

A closure is an inner function that has access to the variables of the outer function.

Closures store references to the variables in the outer function; they do not store the actual values. Closures have access to updating the values of the outer function’s variables.

function showName (firstName, lastName) {

var nameIntro = "Your name is ";

// this inner function has access to the outer function's variables, including the parameter

function makeFullName () {

nameIntro ="我的名字是 "//inner function can change outer function's variable.

return console.log(nameIntro + firstName + " " + lastName);

}

return makeFullName ()

}

showName ("John", "Doe"); // 我的名字是 John Doe

 
function add(x){

    return function(y){

        return x+y;

    };

}

console.log(add(3)(5));//8
<a href="#" onClick="alert('Hi');">Click this link to show a message</a>
<button onclick='getElementById("demo").innerHTML=Date()'>Click me to show what time it is now.</button>

change the content of one element itself, use this.innerHTML instead.

<!-- SHOW HOW MANY TIMES A BUTTON IS CLICKED-->

<!DOCTYPE HTML>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title>Increment count when button is clicked</title>

  </head>



  <body>

    <input type="button" value="Count" id="countButton" />



    <p>The button was pressed <span id="displayCount">0</span> times.</p>



    <script type="text/javascript">

      var count = 0;

      var button = document.getElementById("countButton");

      var display = document.getElementById("displayCount");



      button.onclick = function(){

        count++;

        display.innerHTML = count;

      }

    </script>

  </body>

</html>
//create an empty object

var apple = {};

//create an object and add properties to it
apple= {
    name: "Machintosh",
    color: "Green",
    weight: 100,
    //add method
    display:function(){alert("I weight "+this.weight+" g.");}
};

console.log(apple);

//property change with “.” Dot notation.
apple.color = "Red";

//add the new smell property
apple.smell = "Fresh";

console.log(apple);                

//call the method of the apple object
apple.display();
//result: I weight 100g

//get the value of a propertu
var getValue = apple.weight;
console.log(getValue);   

var person = {
    firstName:"John",
    lastName:"Doe",
    age:50,
    eyeColor:"blue"
};                

console.log(person);
var person = new Object();
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";

console.log(person);
/*The value of “this” when using in a function is the object that the function belongs to. However, when “this” is used in an object, it is the object itself. “this” is a keyword, not a variable, and so its value cannot be changed. */
 

function person(first, last, age, eyecolor) {

    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eyecolor;

    this.changeName = function (name) {
        this.lastName = name;
    }

}


var myFather = new person("John", "Doe", 50, "blue");
console.log(myFather);

var myMother = new person("Sally", "Rally", 48, "green");
console.log(myMother);        

myMother.changeName("Doe");
console.log(myMother);
//using built-in string method

var message = "Hello world!";

var x = message.toUpperCase();

console.log(x);   
var Fruit = function Fruit(name, color) {

    this.name = name; //property
    this.color = color;4. //Method
    this.info = function() {return "I am a " +this.color + " "  + this.name};

}


var Cherry = new Fruit("cherry", "red");
console.log(Cherry);
console.log(Cherry.info());
var user = function (name) {
    this.name = name;
};

var john = new user("John");
console.log(john);
var Fruit = function Fruit(name, color) {
    this.name = name; //property
    this.color = color;
    //Method
    this.info = function() {return "I am a " +this.color + " " + this.name};

}

//This adds a property to the Fruit prototype object
Fruit.prototype.price = 100;

//add new methods to an existing prototype
Fruit.prototype.cost = function() {
    return 'This ' +this.name+' cost ' + this.price;
};


var pear = new Fruit('pear', 'golden');
console.log(pear.price);
//100

console.log(pear.info());
//I am a golden pear

console.log(pear.cost());
//This pear cost 100
var Counter = function(){
    Counter.prototype.count++;
};

Counter.prototype.count = 0;

new Counter();
new Counter();
console.log((new Counter()).count);//3

 

Ivelin Demirov Learn Javascript Visually 立即下载

相关推荐

Learn JavaScript VISUALLY-Ivelin Demirov (2014)

Learn JavaScript VISUALLY , by Ivelin Demirov

JavaScript Learn

JavaScript规范: 1.在html中添加: alert("您好!"); 2.在html 中引用js文件要注意路径 3.在html 中引用 4.注释 //表示单行注释 /** * 多行注释 */ 写函数和变量时候最好有注释,为了一年后能看代码省时间。 5.变量名字和函数名字最好要用驼峰,字...

njiang的专栏 185

Learn JavaScript with p5.js--2018年

Code from scratch and create computer graphics with JavaScript and the p5.js library Gain the necessary skills to move into your own creative projects Create graphics and interactive experiences using Processing Program using JavaScript and p5.js and secondarily in creating visuals

Yii 2 RESTful API 认证(Authentication)完整指南:无状态访问令牌、authenticator 行为与身份实现

本文围绕 Yii 2 框架中 RESTful API 的认证机制展开,核心解决"如何在无会话(stateless)的 API 场景下安全识别请求者身份"这一工程问题。你将掌握三类主流令牌传递方式(HTTP Basic Auth、查询参数、OAuth 2 Bearer Token)在 Yii 2 中的配置方法,理解 `authenticator` 行为(filter)的底层执行链路,并能在自己的 `

gitblog_00004的博客 623

A Smarter Way to Learn JavaScript 无水印pdf

A Smarter Way to Learn JavaScript 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

别再手动抄表了!用PaddleOCR超轻量模型5分钟搞定数字仪表识别(附完整Python代码)

本文介绍如何利用PaddleOCR超轻量模型快速实现工业仪表数字识别自动化。通过5行核心代码和关键预处理步骤,显著提升识别准确率至98.2%,解决传统OCR在工业场景中的体积大、抗干扰弱等问题,并提供完整Python代码和边缘部署优化方案。

weixin_31062533的博客 351

AI编程范式革命:从自动化代码生成到算法深度优化的全景实践

本文探讨了AI编程如何重塑软件工程范式,从传统编码转向"描述需求-生成代码"的新模式。文章系统分析了AI编程的三大核心支柱:1)自动化代码生成,展示如何通过精准Prompt生成复杂API客户端;2)低代码开发,演示如何用自然语言描述生成完整应用;3)算法优化,呈现AI如何将O(n²)算法优化为O(n)。同时深入剖析了Prompt工程技巧、可视化代码生成等高级应用,并客观讨论了当前AI编程在代码质量、安全性等方面的局限性。

zzywxc787的博客 798

ControlCAN.dll开发适配USBCAN_E/2E_U设备

摘要:本文提供了USBCAN_E/2E_U设备的配置指南:1)安装专用驱动;2)获取最新的ControlCAN.dll文件;3)修改VCI调用顺序,新增VCI_SetReference函数设置波特率;4)使用工具计算波特率配置值,并给出了常见波特率对应的代码参考值(如500K对应0x060007)。配置过程强调使用特定工具计算精确的波特率参数,并提供了相关软件下载链接。

weixin_43969033的博客 392

flutter学习笔记

1.跨平台移动UI框架2.与现有的代码一起工作(可以直接嵌入到原生代码中或直接把原生代码嵌入到自己的代码中运行)3. 完全免费、开源。

haoxuhong的博客 8247

【物联网毕设】多模态智能门禁系统设计(STM32+人脸识别+蓝牙联动)

本文详细介绍了基于STM32的多模态智能门禁系统设计,整合了人脸识别、蓝牙联动、RFID和密码等多种开锁方式。文章从硬件选型、电路设计、嵌入式软件编程到手机APP开发,提供了完整的毕设实现方案与调试指南,帮助物联网与嵌入式方向的学生构建一个功能全面、可扩展的智能门禁系统。

rain6的博客 251

apollo自动驾驶进阶学习之:如何实现施工路段限速绕行及其参数调试

首先需要理解Planning模块是基于Scenario、Stage、Task这样的层次来进行的,即场景->步骤->具体的决策方法。Apollo可以应对自动驾驶所面临的不同道路场景,都是通过Scenario统一注册与管理。Scenario通过一个有限状态机来判断选择当前行车场景,每个Scenario下又有多个Stage,指当前场景下需要执行的粗略步骤。.........

qq_41593516的博客 6599

Think Visually:Question Answering through Virtual Imagery读书笔记

设计空间关系的问答,例如描述了一系列物体的位置、大小、包含关系等,最后询问某物体在另一物体的哪个方位。   本文加入了2D空间representation,推理模块使用多跳memory网络...

sjh18813050566的专栏 252

核心组件大换血:Backbone与Neck魔改篇:YOLO26结合StarNet结构:2026星状网络在YOLO生态的即插即用实战

本文将介绍如何将StarNet作为Backbone替换YOLO26原生架构,以提升边缘设备上的目标检测性能。文章首先分析了YOLO26在特定场景下的精度瓶颈,指出其通用Backbone设计存在不足。随后深入解析StarNet的核心创新——星操作(Star Operation),这一低维计算却能获得高维特征表达的数学魔术,以及其极简的StarBlock模块设计。通过对比YOLO26原生架构的三大创新与痛点,作者提出两种替换策略:完整替换Backbone或局部替换+Neck联调。文中提供了StarNet核心代码

ZDQ58818的博客 290

15个免费学习JavaScript的最佳网站

JavaScript是Web最流行的语言。对于任何Web开发人员来说,JavaScript现在是必须学习的语言。像追踪树这样的创新已经大大提高了JavaScript的性能,并且它在所有开...

程序员成长指北 16万+

MATLAB极坐标伪彩色圆图绘制之polarPcolor函数

polarPcolor函数介绍 我们经常在论文或期刊上看到如下图这种以色调冷暖代表数值大小的极坐标圆图, 而function [varargout] = polarPcolor(R,theta,Z,varargin)可以很好的帮助我们快速绘制这类极坐标圆图。它非常适合雷达或激光雷达的平面位置指示器。使用polarPcolor函数时,我们只需根据手中数据构造相应的二维矩阵Z即可,十分便捷。varargin值为绘制模式选择。R值为半径坐标一维矩阵,theta值为角坐标一维矩阵。 代码示例 这里使用了海洋表面耀光

qq_19512613的博客 1万+

蓝牙调试抓包工具--nRF Connect移动端 使用详细总结

摘要: nRF Connect移动端是一款功能全面的蓝牙低功耗(BLE)调试工具,支持设备扫描、多设备连接、服务/特征值查看及数据读写操作。核心功能包括实时数据通信(读取/写入/通知)、设备固件更新(DFU)以及高级工具如自动化测试和信号分析。兼容Android 4.3+和iOS设备,适用于开发调试(如ESP32/nRF52)、设备管理和数据分析。需注意设备兼容性问题(如旧安卓设备可能需关闭连续扫描),并确保数据类型匹配。配套工具链包括nRF Toolbox和nRF Connect SDK,是BLE开发的必

AIoT深度探索者 | 嵌入式系统架构师 深耕物联网(IoT)与人工智能(AI)融合技术,聚焦​​边缘计算、图像开发、低功耗通信协议​​,致力于智能硬件,关注我获取最新技术文章信息与海量资源~ 2390

ACL 2018 ACCEPTED PAPER

ACL 2018接受了258篇长论文和126篇短论文,总体接受率为24.9%。 论文官方地址:https://acl2018.org/programme/papers/ 详细如下: Long Papers A Framework for Representing Language Acquisition in a Population Setting. Jordan Kodner, Christo...

AI小白入门的博客 1万+

面经-2023-禾赛-FPGA工程师

面经-2023-禾赛-FPGA工程师

w0shishabi的博客 2970

Javascript>> onmouseover用法

<!DOCTYPE html> <html> <head> <title>Window Title</title> </head> <body> <p>Test your mouse on me!</p> <script> const p = document.quer...

CodingIsFun 4570

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

用Javascript显示一个电子时钟

<!DOCTYPE html> <html> <head> <style type="text/css" media="screen"> body { background: black; } #txt { position: absolute; top: 50%; left: 50%; transf...

CodingIsFun 2260

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

p5.js: 通过上下左右键控制方块的位置

&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.min.js"&gt;&lt;/script&gt; &lt;style&gt; body { padding: 0;

CodingIsFun 1420

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

JavaScript Basics for Beginners by Mosh Hamedani

Javascript can be run inside a brower or Node which provides a runtime environment for Javascript. ECMAScript is a specification and Javascript is a programming language that confirms to this specifi...

CodingIsFun 949

Learning JavaScript - JavaScript Essentials for Modern Application Development by Ethan Brown

Learning JavaScript JAVASCRIPT ESSENTIALS FOR MODERN APPLICATION DEVELOPMENT by Ethan Brown I certainly hold no animosity toward amateurs: everyone has to start somewhere, programming is a profitabl...

CodingIsFun 700

《Javascript & JQuery interactive front-end web development》 by Jon Duckette 读书笔记-未完待续

There are many inconsistencies between browsers that affect JavaScript developers. jQuery will help you deal with cross-browser inconsistencies (it is one of the major reasons why jQuery rapidly gaine...

CodingIsFun 610
上一篇: How to Have a Better Career in Software by Doug TURNURE from PluralSight 笔记
下一篇: Tips on Using Brackets
CodingIsFun
博客等级 码龄8年 37粉丝 240原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值