1.JS 내장 유형
은 기본 데이터 유형과 Object.
기본 데이터 유형으로 구분됩니다. null , 정의되지 않음, 문자열, 부울, 숫자, 기호.
console.log(typeof null);//object console.log(typeof []);//object console.log(typeof {});//object
널, 배열, 객체를 구별하려면 어떻게 해야 하나요?
如果想要区分null,数组,对象,应该怎么办?
console.log(Object.prototype.toString.call(null));//[object Null] console.log(Object.prototype.toString.call([]));//[object Array] console.log(Object.prototype.toString.call({}));//[object Object]
我的简单理解:toString(数据);作用:将数据转化为字符串。
推荐相关文章:2020年最全js面试题整理(最新)
2.类型转化
类型转化:分为显示类型转化,和隐式类型转化。
1.Number(数据)
如果数据内容式纯粹的数字,才可以转化为数字,否则式NaN。
var str2="12px";//NaN var str2="1.2";//1.2 var str2="1.2.3";//NaN var str2=null;//0 console.log(Number(str2));
2.NaN
NaN的数据类型书Number。注意:NaN和任何东西都不相等,包括自己。
3.isNaN(数据)
会先把数据用Number转化,转化完了之后在判断是不是NaN,如果是NaN则返回为true。否则返回为fasle。
console.log(isNaN(1));//false console.log(isNaN("123"));//false console.log(isNaN("abc"));//true
4.parseInt(数据)和parseFloat(数据)
parseInt(数据):把数据变成整数,舍去小数点,取整数。 parseFloat(数据):把数据转化为数字,可以是小数。 注意:这两个方法会从左往右开始,除去空格,找到第一位非0数字,开始进行转换,直到转换到不是数字的那位为止,或者,转换出合适的值为止。
console.log( parseInt( "1" ) );//1 console.log( parseInt( "1.9" ) );//1 console.log( parseInt( "20px" ) );//20 console.log( parseInt( " 25px" ) );//25 console.log( parseInt( " 0.0026px" ) );//0 console.log( parseFloat( " 0.0026px" ) );//0.0026
5.Stirng( )和Boolean()也可以进行显示类型转化,这里不缀述
条件判断中,除了null,undefined,'',NaN,false,0都转化为false,其余都转化为true。
6.隐式类型转化
只有当加法运算时,其中一方是字符串类型,就会把另一个也转为字符串类型。其他运算只要其中一方是数字,那么另一方就转为数字。并且加法运算会触发三种类型转换:将值转换为原始值,转换为数字,转换为字符串。
<script> console.log( "abc"-1 );//NaN console.log( NaN-1 );//NaN console.log( NaN+1 );//NaN console.log( NaN+"1" );//NaN1 //------------------------------------------ console.log( "3"-1 );//转成数字2 console.log( "345" - 0 );//转成数字345 console.log( "345" * 1 );//转成数字345 console.log( "345" / 1 );//转成数字345 console.log( "345px" - 0 );//NaN //------------------------------------------ console.log( 123 + "" );//转成字符串 "123" //------------------------------------------ console.log( !!234 );//转成boolean类型 true console.log( !!0 );//转成boolean类型 false console.log( !!{} );//转成boolean类型 true console.log( !!null );//转成boolean类型 false
3.运算符
==和===
==: 1.如果类型相同的话,比较内容 类型不相同,类型转化在比较 1)一个是undefined,一个是null,则相等。 2)数字和字符串的的话,将字符串转化为数字再进行比较。 ===: 1.类型相同比教内容,类型不同则返回fasle。
4.原型,原型链,new
1.new
1.新生成了一个对象 2.链接到原型 3.绑定this 4.返回新对象
2.prototype 原型
prototype 原型 当一个函数被申明的时候,该函数下默认有一个属性:prototype,该属性的值是一个对象 当我们去调用一个对象的属性或者方法的时候,如果该对象自身没有该属性或方法, 则会调用到该对象 的 构造函数的prototype的属性或方法 把通过构造函数构造出来的对象,共有的方法或者属性,放在prototype身上 __proto__ 当一个对象被创建的时候, 该对象会自动被添加上一个属性:__proto__, 他的值也是一个对象,并且该属性 就是 当前这个对象的构造函数的prototype 对象.__proto__ === 构造函数.prototype
3.原型链
Function.prototype.a = "a"; Object.prototype.b = "b"; function Person(){} console.log(Person); //function Person() let p = new Person(); console.log(p); //Person {} 对象 console.log(p.a); //undefined console.log(p.b); //b
解析:
会一直通过__proto__向上查找,最后当查找到Object.prototype时找到,最后打印出b,向上查找过程中,得到的是Object.prototype,而不是Function.prototype,找不到a属性,所以结果为undefined,这就是原型链,通过__proto__向上进行查找,最终到null结束
//Function function Function(){} console.log(Function); //Function() console.log(Function.prototype.constructor); //Function() console.log(Function.prototype.__proto__); //Object.prototype console.log(Function.prototype.__proto__.__proto__); //NULL console.log(Function.prototype.__proto__.constructor); //Object() console.log(Function.prototype.__proto__ === Object.prototype); //true
总结:
1.查找属性,如果本身没有,则会去__proto__中查找,也就是构造函数的显式原型中查找,如果构造函数中也没有该属性,因为构造函数也是对象,也有__proto__,那么会去它的显式原型中查找,一直到null,如果没有则返回undefined 2.p.__proto__.constructor == function Person(){} 3.p.___proto__.__proto__== Object.prototype 4.p.___proto__.__proto__.__proto__== Object.prototype.__proto__ == null 5.通过__proto__形成原型链而非protrotype
5.instanceof
检测对象原型是否在要检测对象的原型链上,返回值为true或者false 使用:object instanceof constructor
function Fn () {} var f = new Fn(); console.log( f instanceof Fn );//true console.log( f instanceof Object );//true
// //str是字面量生成的,是由JS内部的String构造函数new出来的。 // //但是str会立刻"压扁"自己,让自己不是对象。 // //所以str都不是对象了,自然instanceof String 的得到的值为fasle // //但str.indexOf(),str还是可以调用indexOf()方法的原因是,当它调用方法的时候,会重新将自己包装成对象。 // //使用结束后会重新"压扁"自己,让自己不是对象。 var str = "123"; console.log( str instanceof Array );//false console.log( str instanceof String);//false console.log( str instanceof Object);//false // var obj = {}; console.log( obj instanceof Array );//false console.log( obj instanceof Object);//true
6.hasOwnProperty
作用 用来判断某个对象是否含有 指定的 自身属性 语法 boolean object.hasOwnProperty(prop) 参数 object 要检测的对象 prop 要检测的属性名称。 注意:不会沿着原型链查找属性,只查找自身属性
function Fn(name,gender){ this.name = name; this.gender = gender; } Fn.prototype.kind = "human"; Fn.prototype.say = function(){ console.log(1); }; var f = new Fn("kimoo","男"); console.log( f.hasOwnProperty("name") ); //true console.log( f.hasOwnProperty("kind") ); //false console.log( f.hasOwnProperty("say") ); //false
8.call,bind,apply
call,bind,apply的作用都是修改this指向。
区别:
1.call:函数会立即执行,括号中的内容 第一个参数 就是 函数执行时候 ,内部的this指向。后面的参数就是函数内部的实参。
function foo (a,b) { console.log( this ); console.log( a,b ); } foo.call( document,2,3 );//运行结果:#document 2,3
2.apply:函数会立即执行,括号中的内容 第一个参数 就是 函数执行时候 ,内部的this指向。不过第二个参数接受数组。
function foo (a,b) { console.log( this ); console.log( a,b ); } foo.apply( document,[2,3] ); // 和call 相似 直接调用 , 不过第二个参数接受数组。运行结果:#document 2,3
3.bind:函数 不会 立刻执行,返回的是 修改了 this指向的新函数.第二个参数是参数列表。
function foo (a,b) { console.log( this ); console.log( a,b ); } var fn = foo.bind( document,2,3);// 函数 不会 立刻执行,返回的是 修改了 this指向的新函数 fn(); //运行结果: //#document //2 3
9.组合式继承
<script> function Person(){ this.arr = [1,2,3]; this.age = 10; } Person.prototype.say = function(){ console.log( "我会说话" ); }; // 父类构造函数中的方法,使用借用构造函数的方式继承 function Coder(name,money) { Person.call(this); this.name = name; this.money = money; } // 父类构造函数原型上的方法,使用原型链继承 Coder.prototype = new Person(); Coder.prototype.constructor = Coder; // 重新修改 constructor Coder.prototype.say = function(){ console.log( "我是程序员,我叫" + this.name +",我一个月:"+ this.money ); } var p = new Person(); console.log( p.age ); console.log( p.arr ); console.log( p.kind ); p.say(); var c1 = new Coder("a",10000); console.log( c1.age ); c1.say(); c1.arr.push(4); console.log( c1.arr ); console.log( c1.name ); console.log( c1.money ); var c2 = new Coder("b",30000); c2.say(); console.log( c2.age ); console.log( c2.arr ); console.log( c2.name ); console.log( c2.money ); console.log(Coder.prototype.constructor); </script>
10.拷贝式继承
<script> function Person(){ this.arr = [1,2,3]; this.age = 10; } Person.prototype.say = function(){ console.log( "我会说话" ); } function Coder(){ Person.call(this); } Coder.prototype = cloneFn( Person.prototype ); Coder.prototype.constructor = Coder; Coder.prototype.say = function(){ console.log( "我是程序员" ); } var p = new Person(); console.log( p.age ); console.log( p.arr ); p.say(); console.log( "----------------" ); var c1 = new Coder(); console.log( c1.age ); c1.say(); c1.arr.push(4); console.log( c1.arr ); console.log( "----------------" ); var c2 = new Coder(); console.log( c2.age ); console.log( c2.arr ); c2.say(); //------------------------------------------ function cloneFn( sourse ){ var o = Object.prototype.toString.call(sourse).toLowerCase().indexOf("array")!==-1 ? [] : {}; for( var attr in sourse ){ if( (typeof sourse[attr] === "object") && sourse[attr] !== null ){ o[attr] = cloneFn( sourse[attr] ) ; }else{ o[attr] = sourse[attr]; } } return o; } </script>
11.class继承
<script> class Person { constructor(name){ this.name = name; } say(){ console.log( '我的名字叫 ${this.name}'); } } class Coder extends Person{ // constructor( name,money ){ // super(name); // 相当于 调用 父类的 构造函数,修改内部的this, //// 一定要先调用 super 再使用 this // this.money = money; // } say(){ console.log( `我的名字叫 ${this.name}` ); } eat(){ console.log( "我会吃" ); } } var p = new Person("kimoo"); // console.log( p ); // p.say(); // p.eat(); // 报错: p.eat is not a function var c = new Coder("zm"); console.log( c ); c.say(); c.eat(); </script>
12.函数作用域,执行上下文,变量提升,闭包
1.作用域
JS作用域分为全局作用域和函数作用域,函数作用域可以访问全局作用域中的变量,对象,函数等。但是函数作用域外部访问不到函数内部的变量,对象,函数。 但在ES6中新增了块级作用域。let,const在块中声明的变量,函数等,外部都访问不到。
{ var a=1; let b=2; console.log(b);//2 { console.log(b);//2 } } console.log(a);//1 console.log(b);//报错,b is not defined
2.执行上下文
这里有篇非常好的js执行上下文的文章,可以点击链接查看
总结:
1. 调用函数是会为其创建执行上下文,并压入执行环境栈的栈顶,执行完毕弹出,执行上下文被销毁,随之VO也被销毁 2. EC创建阶段分创建阶段和代码执行阶段 3. 创建阶段初始变量值为undefined,执行阶段才为变量赋值 4. 函数申明先于变量申明
3.变量提升(域解析)
关键:变量提升过程中函数优先级高于变量优先级
function foo() { console.log(f1); //f1() {} console.log(f2); //undefined var f1 = 'hosting'; var f2 = function() {} function f1() {} } foo();
4.闭包
for ( var i=1; i<=5; i++) { setTimeout( function timer() { console.log( i ); }, i*1000 ); }
나의 간단한 이해: toString(data) 기능: 데이터를 문자열로 변환합니다.
추천 관련 기사: 2020년 가장 포괄적인 js 인터뷰 질문 모음(최신) # 🎜🎜 #
2. 유형 변환
유형 변환: 명시적 유형 변환과 암시적 유형 변환으로 구분됩니다.
1.번호(데이터)for (var i = 1; i <= 5; i++) { (function(j) { setTimeout(function timer() { console.log(j); }, j * 1000); })(i); }
for ( var i=1; i<=5; i++) { setTimeout( function timer(j) { console.log( j ); }, i*1000, i); }
2.NaN
for ( let i=1; i<=5; i++) { setTimeout( function timer() { console.log( i ); }, i*1000 ); }#🎜🎜 #
3.isNaN(데이터)
let a = { age: 1 } let b = Object.assign({}, a) a.age = 2 console.log(b.age) // 1rrree
4.parseInt(데이터) 및 parseFloat(데이터)
let a = { age: 1 } let b = {...a} a.age = 2 console.log(b.age) // 1rrree#🎜 🎜#5. Stirng( ) 및 Boolean()은 여기서 설명하지 않는 명시적 유형 변환도 수행할 수 있습니다
function cloneFn( sourse ){ var o = Object.prototype.toString.call(sourse).toLowerCase().indexOf("array")!==-1 ? [] : {}; for( var attr in sourse ){ if( (typeof sourse[attr] === "object") && sourse[attr] !== null ){ o[attr] = cloneFn( sourse[attr] ) ; }else{ o[attr] = sourse[attr]; } } return o; }
6. # 🎜🎜#rrreeerrreee3. 연산자
== 및 ===rrreee4. #
#🎜🎜#1.new
#🎜🎜##🎜🎜#rrreee#🎜🎜##🎜🎜#2.프로토타입 프로토타입
#🎜🎜 ##🎜🎜#rrreee#🎜🎜##🎜🎜#3. 프로토타입 체인
#🎜🎜##🎜🎜#rrreee#🎜🎜# 분석: #🎜🎜#rrreeerrree#🎜🎜## 🎜🎜#요약: #🎜🎜##🎜🎜#rrreee#🎜🎜#5.instanceof#🎜🎜#rrreeerrreeerrreee#🎜🎜#6.hasOwnProperty#🎜🎜#rrreeerrreee#🎜🎜#8.call,bin d,신청# 🎜🎜##🎜🎜##🎜🎜#call, 바인딩, 적용 기능은 이 포인터를 수정하는 것입니다. #🎜🎜##🎜🎜##🎜🎜##🎜🎜#차이:#🎜🎜##🎜🎜#rrreeerrreeerrreeerrreeerrreeerrreee#🎜🎜#9. 0. 상속 복사 #🎜 🎜#rrreee#🎜🎜#11.클래스 상속#🎜🎜#rrreee#🎜🎜#12. 함수 범위, 실행 컨텍스트, 변수 승격, 클로저#🎜🎜##🎜🎜##🎜🎜#1. ##🎜🎜#rrreeerrreee#🎜🎜##🎜🎜#2. 실행 컨텍스트#🎜🎜##🎜🎜#js 실행 컨텍스트에 대한 아주 좋은 기사가 있습니다. 링크를 클릭하면 볼 수 있습니다#🎜🎜 ##🎜 🎜##🎜🎜#요약: #🎜🎜##🎜🎜#rrreee#🎜🎜##🎜🎜#3. 변수 승격(도메인 해상도) #🎜🎜##🎜🎜##🎜🎜##🎜 🎜#Key : #🎜🎜#변수 승격 중 #🎜🎜#함수 우선순위가 변수 우선순위보다 높습니다#🎜🎜##🎜🎜#rrreee#🎜🎜##🎜🎜#클로저 code>#🎜🎜# #🎜🎜##🎜🎜##🎜🎜#Closure: 함수 A는 함수 B를 반환하고, 함수 B는 함수 A의 변수를 사용하며, 함수 B를 클로저라고 합니다. #🎜🎜##🎜🎜#rrreee#🎜🎜#먼저 setTimeout은 비동기 함수이기 때문에 모든 루프가 먼저 실행됩니다. 이때 i는 6이므로 6이 잔뜩 출력됩니다. #🎜🎜##🎜🎜#솔루션 1: #🎜🎜#rrreee#🎜🎜#솔루션 2: #🎜🎜#rrreee#🎜🎜#솔루션 3: #🎜🎜#rrreee#🎜🎜#여기를 클릭하세요. 자세히 알아보기 클로저#🎜🎜##🎜🎜#13. 깊고 얕은 사본#🎜🎜##🎜🎜##🎜🎜#1. 얕은 사본#🎜🎜##🎜🎜##🎜🎜#먼저 Object.sign을 전달할 수 있습니다. 이 문제를 해결하기 위해. #🎜🎜#rrreee#🎜🎜#물론 스프레드 연산자를 통해서도 해결할 수 있습니다(…)#🎜🎜#rrreee#🎜🎜##🎜🎜#2 Deep copy#🎜🎜##🎜🎜#rrreee# 🎜 🎜#관련글 : #🎜🎜##🎜🎜##🎜🎜##🎜🎜#8 JS에서 꼭 주의해야 할 기본지식#🎜🎜##🎜🎜##🎜🎜##🎜🎜#Javascript 기초지식 정리 #🎜🎜##🎜🎜#
위 내용은 필수 JS 기본 지식 – 일반적인 면접 질문을 체계적으로 정리의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

일상적인 기술 도구를 사용하여 기능적 다중 테넌트 SaaS 응용 프로그램 (Edtech 앱)을 구축했으며 동일한 작업을 수행 할 수 있습니다. 먼저, 다중 테넌트 SaaS 응용 프로그램은 무엇입니까? 멀티 테넌트 SAAS 응용 프로그램은 노래에서 여러 고객에게 서비스를 제공 할 수 있습니다.

이 기사에서는 Contrim에 의해 확보 된 백엔드와의 프론트 엔드 통합을 보여 주며 Next.js를 사용하여 기능적인 Edtech SaaS 응용 프로그램을 구축합니다. Frontend는 UI 가시성을 제어하기 위해 사용자 권한을 가져오고 API가 역할 기반을 준수하도록합니다.

JavaScript는 현대 웹 개발의 핵심 언어이며 다양성과 유연성에 널리 사용됩니다. 1) 프론트 엔드 개발 : DOM 운영 및 최신 프레임 워크 (예 : React, Vue.js, Angular)를 통해 동적 웹 페이지 및 단일 페이지 응용 프로그램을 구축합니다. 2) 서버 측 개발 : Node.js는 비 차단 I/O 모델을 사용하여 높은 동시성 및 실시간 응용 프로그램을 처리합니다. 3) 모바일 및 데스크탑 애플리케이션 개발 : 크로스 플랫폼 개발은 개발 효율을 향상시키기 위해 반응 및 전자를 통해 실현됩니다.

JavaScript의 최신 트렌드에는 Typescript의 Rise, 현대 프레임 워크 및 라이브러리의 인기 및 WebAssembly의 적용이 포함됩니다. 향후 전망은보다 강력한 유형 시스템, 서버 측 JavaScript 개발, 인공 지능 및 기계 학습의 확장, IoT 및 Edge 컴퓨팅의 잠재력을 포함합니다.

JavaScript는 현대 웹 개발의 초석이며 주요 기능에는 이벤트 중심 프로그래밍, 동적 컨텐츠 생성 및 비동기 프로그래밍이 포함됩니다. 1) 이벤트 중심 프로그래밍을 사용하면 사용자 작업에 따라 웹 페이지가 동적으로 변경 될 수 있습니다. 2) 동적 컨텐츠 생성을 사용하면 조건에 따라 페이지 컨텐츠를 조정할 수 있습니다. 3) 비동기 프로그래밍은 사용자 인터페이스가 차단되지 않도록합니다. JavaScript는 웹 상호 작용, 단일 페이지 응용 프로그램 및 서버 측 개발에 널리 사용되며 사용자 경험 및 크로스 플랫폼 개발의 유연성을 크게 향상시킵니다.

Python은 데이터 과학 및 기계 학습에 더 적합한 반면 JavaScript는 프론트 엔드 및 풀 스택 개발에 더 적합합니다. 1. Python은 간결한 구문 및 풍부한 라이브러리 생태계로 유명하며 데이터 분석 및 웹 개발에 적합합니다. 2. JavaScript는 프론트 엔드 개발의 핵심입니다. Node.js는 서버 측 프로그래밍을 지원하며 풀 스택 개발에 적합합니다.

JavaScript는 이미 최신 브라우저에 내장되어 있기 때문에 설치가 필요하지 않습니다. 시작하려면 텍스트 편집기와 브라우저 만 있으면됩니다. 1) 브라우저 환경에서 태그를 통해 HTML 파일을 포함하여 실행하십시오. 2) Node.js 환경에서 Node.js를 다운로드하고 설치 한 후 명령 줄을 통해 JavaScript 파일을 실행하십시오.

쿼츠 타이머를 사용하여 작업을 예약 할 때 미리 쿼츠에서 작업 알림을 보내는 방법 작업의 실행 시간은 CRON 표현식에 의해 설정됩니다. 지금...


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

드림위버 CS6
시각적 웹 개발 도구

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음
