【Javascript】Day1:Javascript Fundamentals

Hello World!

Chrome (brower) developer tools

  1. Ctrl+Shift+J → Console
  2. 右键+检查 → Element
    Hello World!Javascript with logic

A Brief Introduction to Javascript

What is Javascript?

JS定义与解释
multi-paradigm: such as imperative and declarative programming 命令式和声明式编程

The role of JS in web development

Web三组件
HTML(结构)、CSS(表现)、Javascript(行为)

Javascript can do anything!

没有很懂,后续搞懂

Javascript Releases

JS版本

Link A Javascript File

外部引入JS文件

  1. 新建JS文件
    新建js文件
  2. HTML文件中引入
    在body标签内的底部,链接上JS脚本
<body>
  <h1>JavaScript Fundamentals – Part 1</h1>
  <script src="script.js"></script>
</body>

Values And Variables

declare the variable with the value

let firstName = "Xu";

variable like a box that can contain everything

conventions and rules for naming variables

  1. camelCase;
let firstName = "Jonas";
let first_name_person = "Jonas";    //also right 
  1. not start with a number;
let 3years = 3;     //wrong

报错信息(without use of console.log )
语法错误提示

  1. only contain numbers, letters, underscores, or the dollar sign ($);
  2. not use a JS keyword as a variable name;
let new = 27;     //wrong
let function = 88;     //wrong
let _function = 88;     //right

报错信息
在这里插入图片描述
特殊情况

let name = "jonas"   //不会报错,但不符合惯例
  1. not start a variable name with an uppercase letter;
let Person = "jonas";     //legal but not conventional

以大写字母开头的名称用于面向对象编程

  1. a constant in all upper case;
    永远不会改变的常量
let PI = 3.1415;
  1. descriptive naming
//easy to understand
let myFirstJob = "Programmer”;
let myCurrentJob = "Teacher”;

let job1 = "Programmer”
let job2 = "Teacher”;

Data Types

Object and Primitives

对象与初始值

The 7 Primitive Data Types

数据类型
code comment

//单行注释 Ctrl+/

/* 
    多行注释
*/
  1. boolean
let javaScriptIsFun = true;
console.log(javaScriptIsFun);

//typeof: a special operator, show the type of value
console.log(typeof true);
console.log(typeof javaScriptIsFun);

boolean值

  1. string
    use quotes to create a string, or this’s just a variable.
    在这里插入图片描述
  2. dynamic typing
    let (keyword): the first time we declare a new variable
let javaScriptIsFun = true;
console.log(javaScriptIsFun);
console.log(typeof javaScriptIsFun);

javaScriptIsFun = 'YES!';
console.log(javaScriptIsFun);
console.log(typeof javaScriptIsFun);

结果

  1. undefined & null
let year;
console.log(year);
console.log(typeof year);

year = 1991;
console.log(year);
console.log(typeof year);

console.log(typeof null);

在这里插入图片描述

let, const and var

three ways of declaring variables

let

let age = 30;
//reassign a value to a variable, or mutate the age variable
age = 31;

//
let year;
year = 1991

const

an immutable variable

//the value in a const variable cannot be changed
const birthYear = 1991;
birthYear = 1990; //wrong1

//cannot declare empty const variables
const job;  //wrong2

wrong1

wrong2

var

var job = 'programmer';
job = 'teacher';

difference: let is block-scoped, var is function-scoped

not declaring

//doesn't create a variable in the current so-called scope
//js will create a property on global object
lastName = 'Xu';
console.log(lastName);

it can present the result, but don’t use this way
在这里插入图片描述

Notes

Just use let and const to declare variables. If you need to change the value in the variable, use let to declare. Otherwise use const.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"JavaScript engine fundamentals: Shapes and Inline Caches" 是指JavaScript引擎的基本概念:Shapes(形状)和Inline Caches(内联缓存)。 1. Shapes(形状):在JavaScript引擎中,每个对象都有一个形状,用于描述对象的结构和属性。形状包含对象的属性名称、偏移量和其他相关信息。当创建一个新对象时,引擎会根据对象的属性来确定其形状,并将该形状与对象关联起来。这样,在后续对同一形状的对象进行操作时,引擎可以更高效地执行。 形状对于优化JavaScript代码的执行非常重要。引擎可以根据对象的形状来进行内存布局和属性访问的优化,提高代码的执行效率。如果对象的形状发生变化(例如添加或删除属性),引擎会为该对象创建一个新的形状,并相应地调整相关操作。 2. Inline Caches(内联缓存):内联缓存是一种用于加速函数调用和属性访问的技术。当使用JavaScript代码调用函数或访问对象属性时,引擎会在编译阶段生成内联缓存,将函数调用或属性访问与特定的对象关联起来。 内联缓存可以避免每次函数调用或属性访问时都进行动态查找和解析。引擎会根据对象的形状和属性的特征,将函数调用或属性访问的地址直接嵌入到代码中。这样,在后续对同一对象进行函数调用或属性访问时,引擎可以直接使用内联缓存中的地址,避免了额外的查找和解析开销。 通过使用Shapes和Inline Caches,JavaScript引擎可以提高代码的执行效率和性能,加快函数调用和属性访问的速度。这些基本概念是JavaScript引擎优化和执行的关键部分。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值