JavaScript笔记(基础)

1.
------------------------------------------------------------------------------------------
JavaScript can "display" data in different ways:

Writing into an alert box, using window.alert().
Writing into the HTML output using document.write().
Writing into an HTML element, using innerHTML.
Writing into the browser console, using console.log().

Using document.write() after an HTML document is fully loaded, will delete all existing HTML: The document.write() method should be used only for testing.

下面这种的就不会:
<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
window.alert(5 + 6);
</script>

</body>
</html>

------------------------------------------------------------------------------------------
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type

var x = new String("John");
var y = new String("John");
// (x == y) is false because x and y are different objects
// (x == x) is true because both are the same object
------------------------------------------------------------------------------------------
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object type

-----------------------------------------------------------------------------------------

var cars = ["Saab", "Volvo", "BMW"]; // Array
var x = {firstName:"John", lastName:"Doe"}; // Object

----------------------------------------------------------------------------------------
JavaScript evaluates expressions from left to right. Different sequences can produce different results:
var x = 16 + 4 + "Volvo";
Result: 20Volvo

----------------------------------------------------------------------------------------
array is an object too
typeof [1,2,3,4] // Returns object
typeof {name:‘John‘, age:34} // Returns object
----------------------------------------------------------------------------------------
var person; // Value is undefined, type is undefined
person = undefined; // Value is undefined, type is undefined
var person = null; // Value is null, but type is still an object
null === undefined // false
null == undefined // true
-------------------------------------------------------------------------------------------
调用函数不加括号,就是打印函数
function toCelsius() {
return (5/9) ;
}
document.getElementById("demo").innerHTML = toCelsius; //这个就是打印这个函数,而不是调用
------------------------------------------------------------------------------------------

js就是贱,没有class就可以有对象了。。。

<script>
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
document.getElementById("demo").innerHTML =
person.firstName + " is " + person.age + " years old.";
</script>
------------------------------------------------------------------------------------------

You can access object properties in two ways:

objectName.propertyName
or
objectName["propertyName"]
-----------------------------------------------------------------------------------------
Do Not Declare Strings, Numbers, and Booleans as Objects!
When a JavaScript variable is declared with the keyword "new", the variable is created as an object:
千万别这么干。。。
var x = new String(); // Declares x as a String object
var y = new Number(); // Declares y as a Number object
var z = new Boolean(); // Declares z as a Boolean object
但是可以直接当对象来用
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sln = txt.length;
-------------------------------------------------------------------------------------------
//If you assign a value to a variable that has not been declared, it will automatically become a GLOBAL variable.
// code here can use carName
function myFunction() {
carName = "Volvo";

// code here can use carName

}
--------------------------------------------------------------------------------------------
事件:

Event Description
onchange An HTML element has been changed
onclick The user clicks an HTML element
onmouseover The user moves the mouse over an HTML element
onmouseout The user moves the mouse away from an HTML element
onkeydown The user pushes a keyboard key
onload The browser has finished loading the page
---------------------------------------------------------------------------------------------
字符串:

String Properties
constructor Returns the function that created the String object‘s prototype
length Returns the length of a string
prototype Allows you to add properties and methods to an object

String Methods
charAt() Returns the character at the specified index (position)
charCodeAt() Returns the Unicode of the character at the specified index
concat() Joins two or more strings, and returns a copy of the joined strings
fromCharCode() Converts Unicode values to characters
indexOf() Returns the position of the first found occurrence of a specified value in a string
lastIndexOf() Returns the position of the last found occurrence of a specified value in a string
localeCompare() Compares two strings in the current locale
match() Searches a string for a match against a regular expression, and returns the matches
replace() Searches a string for a value and returns a new string with the value replaced
search() Searches a string for a value and returns the position of the match
slice() Extracts a part of a string and returns a new string
split() Splits a string into an array of substrings
substr() Extracts a part of a string from a start position through a number of characters
substring() Extracts a part of a string between two specified positions
toLocaleLowerCase() Converts a string to lowercase letters, according to the host‘s locale
toLocaleUpperCase() Converts a string to uppercase letters, according to the host‘s locale
toLowerCase() Converts a string to lowercase letters
toString() Returns the value of a String object
toUpperCase() Converts a string to uppercase letters
trim() Removes whitespace from both ends of a string
valueOf() Returns the primitive value of a String object
-----------------------------------------------------------------------------------------------
数字:

Property Description
MAX_VALUE Returns the largest number possible in JavaScript
MIN_VALUE Returns the smallest number possible in JavaScript
NEGATIVE_INFINITY Represents negative infinity (returned on overflow)
NaN Represents a "Not-a-Number" value
POSITIVE_INFINITY Represents infinity (returned on overflow)
----------------------------------------------------------------------------------------------

时间: 2024-10-13 23:16:33

JavaScript笔记(基础)的相关文章

JavaScript笔记基础篇(二)

基础篇主要是总结一些工作中遇到的技术问题是如何解决的,应为本人属于刚入行阶段技术并非大神如果笔记中有哪些错误,或者自己的一些想法希望大家多多交流互相学习. 1.ToFixed()函数 今天在做Birt报表时, 要显示一列百分比的数据,但因一些特别的原因,不能使用使用百分比样式,即如果数据是0.9538不能显示成“95.38%”的样式,必须显示成“95.38”. 开始时想使用javascript的内置函数Math.round(),可Math.round()只能显示为整数,而不能保留小数. 再网上搜

javascript笔记基础总结篇

Created at 2016-09-24 Updated at 2016-10-02 CategoryFront-End TagJavascript 转载请声明出处博客原文 随手翻阅以前的学习笔记,顺便整理一下放在这里,方便自己复习,也希望你有也有帮助吧 第一课时 入门基础 知识点: 操作系统就是个应用程序 只要是应用程序都要占用物理内存 浏览器本身也是一个应用程序 浏览器本身只懂得解析 HTML 调用浏览器这个应用程序的一个功能绘制 1.javascript介绍 JavaScript 操作 

JavaScript笔记——基础知识(二)

Function类型 函数function不需要返回类型(不是没有返回值),参数也不需要指定类型,更为特殊的是函数竟然是个类,可以通过new出来 var box= new Function('num1', 'num2' ,'return num1 + num2'); 这样的写法是完全正确的,但不推荐使用,因为会解析两次(第一次解析JavaScript代码,第二次解析参数)造成性能问题 function可以当做参数使用 (很怪异,方法作为参数, 可以理解成把函数的引用作为参数) function

JavaScript笔记基础篇(三)

针对前段JS获取当前时间或者对时间数据处理方法汇总: javascript 字符串转化为日期 Java代码   var s="2010-5-18 12:30:20"; var t=new Date(s.replace(/-/g,"/")); java代码 Java代码   <% SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); Date Acceptdate 

JavaScript笔记基础篇(一)

一. 常用正则表达式汇总以及部分问题解决方案 正则匹配: var str = "This is my test"; var test = new RegExp("test","g");//创建正则表达式对象 var result = s.match(test); alert(result); 1.常用正则表达式: 验证数字的正则表达式集  验证数字:^[0-9]*$  验证n位的数字:^\d{n}$  验证至少n位数字:^\d{n,}$  验证m

javascript的基础知识及面向对象和原型属性

自己总结一下javascript的基础知识,希望对大家有用,也希望大家来拍砖,毕竟是个人的理解啊 1.1 类型检查:typeof(验证数据类型是:string) var num = 123; console.log(typeof num); // 1.2 in 运算符 作用:判断指定属性是否存在于指定的对象中. 如果指定的属性存在于指定的对象中,则 in 运算符会返回 true. 语法: 属性 in 对象 返回值:true 或者 false 示例: var obj = { age: 18 };

JavaScript继承基础讲解,原型链、借用构造函数、混合模式、原型式继承、寄生式继承、寄生组合式继承

说好的讲解JavaScript继承,可是迟迟到现在讲解.废话不多说,直接进入正题. 既然你想了解继承,证明你对JavaScript面向对象已经有一定的了解,如还有什么不理解的可以参考<面向对象JS基础讲解,工厂模式.构造函数模式.原型模式.混合模式.动态原型模式>,接下来讲一般通过那些方法完成JavaScript的继承. 原型链 JavaScript中实现继承最简单的方式就是使用原型链,将子类型的原型指向父类型的实例即可,即“子类型.prototype = new 父类型();”,实现方法如下

JavaScript笔记之Function

一.函数定义 (1)使用function declaration 格式:function functionName(parameters) { function body } 注:此种方式声明的函数作用域是全局的,即在声明之前可以调用 (2)使用function expression 格式:var name = function (parameters) { function body }; 注:与(1)不同,在声明之前不可以调用 (3)使用function constructor() 格式:v

JavaScript 语言基础知识点总结(思维导图)

1.JavaScript数组 2.JavaScript 函数基础 3.Javascript 运算符 4.JavaScript 流程控制 5.JavaScript 正则表达式 6.JavaScript 变量 7.JavaScript 字符串函数 8.DOM 基本操作

JavaScript语言基础知识点图示

原文:JavaScript语言基础知识点图示 一位牛人归纳的JavaScript 语言基础知识点图示. 1.JavaScript 数据类型 2.JavaScript 变量 3.Javascript 运算符 4.JavaScript 数组 5.JavaScript 流程控制 6.JavaScript 函数基础 7.DOM 基本操作 8.Window 对象 9.JavaScript 字符串函数 10.正则表达式 JavaScript语言基础知识点图示,布布扣,bubuko.com