JavaScript - 编译性还是解释性?

疑问

在JS的变量和声明式函数的提升看到了“预编译/预处理/预解释”中“预编译”这个字眼,产生了一个疑问:JS是熟知的解释性语言,但JS能被编译吗?

参考

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScriptJavaScript (JS) is a lightweight interpreted or JIT-compiled programming language** with first-class functions.**
  2. https://zh.wikipedia.org/wiki/JavaScript :** 在客户端,JavaScript在传统意义上被实现为一种解释语言,但在最近,它已经可以被即时编译(JIT)执行。**
  3. https://stackoverflow.com/questions/26709524/javascript-compiled-language
  4. https://www.quora.com/Is-JavaScript-a-compiled-or-interpreted-programming-languageJavaScript used to be purely interpreted but that was many years ago. Nowadays, it is JIT-compiled to native machine code in all major JavaScript implementations.
  5. https://en.wikipedia.org/wiki/Chrome_V8V8 compiles JavaScript directly to native machine code before executing it, instead of more traditional techniques such as interpreting bytecode or compiling the whole program to machine code and executing it from a filesystem.
  6. https://github.com/v8/v8/wiki/IntroductionV8 compiles and executes JavaScript source code, handles memory allocation for objects, and garbage collects objects it no longer needs.
  7. https://softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design
  8. https://segmentfault.com/a/1190000013126460
  9. https://www.zhihu.com/question/31415286/answer/58022648

总结

chrome V8可以编译JS to native code
所以JS是一门解释性语言,有编译特性(取决于引擎)。另外,Python是解释性语言,也有编译特性(要查看具体原理)。
一般来说,JS先解析(例如进行变量、函数的提升声明),再运行。

转载于:https://www.cnblogs.com/allen2333/p/9148230.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值