{"action":"opened","issue":{"url":"https://api.github.com/repos/muwenzi/Blog/issues/34","repository_url":"https://api.github.com/repos/muwenzi/Blog","labels_url":"https://api.github.com/repos/muwenzi/Blog/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/muwenzi/Blog/issues/34/comments","events_url":"https://api.github.com/repos/muwenzi/Blog/issues/34/events","html_url":"https://github.com/muwenzi/Blog/issues/34","id":183264988,"number":34,"title":"JS是动态弱类型语言的理解","user":{"login":"muwenzi","id":12554487,"avatar_url":"https://avatars.githubusercontent.com/u/12554487?v=3","gravatar_id":"","url":"https://api.github.com/users/muwenzi","html_url":"https://github.com/muwenzi","followers_url":"https://api.github.com/users/muwenzi/followers","following_url":"https://api.github.com/users/muwenzi/following{/other_user}","gists_url":"https://api.github.com/users/muwenzi/gists{/gist_id}","starred_url":"https://api.github.com/users/muwenzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muwenzi/subscriptions","organizations_url":"https://api.github.com/users/muwenzi/orgs","repos_url":"https://api.github.com/users/muwenzi/repos","events_url":"https://api.github.com/users/muwenzi/events{/privacy}","received_events_url":"https://api.github.com/users/muwenzi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/muwenzi/Blog/labels/ES5","name":"ES5","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-16T12:40:16Z","updated_at":"2016-10-16T12:40:16Z","closed_at":null,"body":"## 背景\r\n常常说JS是一门动态语言或是弱类型的语言，今天看到[阮一峰老师写的一篇文章](http://www.ruanyifeng.com/blog/2015/02/strong-typing-javascript.html)中的貌似开始也木有分清，故在次端正一下我的三观，加深对其理解。\r\n\r\n**强弱，动静是两个概念**\r\n```\r\nPython是强类型 + 动态类型\r\nJS是弱类型 + 动态类型\r\n```\r\n\r\n## 举个🌰\r\nx 可以一会是字符串，一会是浮点，这是动态。\r\n3/\"1.5\" 这个数字除字符串合法是弱类型（场合时自动帮你转类型）\r\n\r\n## 定义\r\n```\r\n动态/静态类型，指的是声明一个变量之后，它是否可以存储（指向）不同类型的变量。\r\n```\r\n\r\n比如C语言，变量声明的时候是数字类型的，这个变量就不能赋予整数类型的内容，这就是静态类型。在Javascript中，变量是没有固定类型的，可以动态变化类型，所以，你可以最初的时候声明为数字，然后在赋值为字符串，这叫动态类型。\r\n\r\n```\r\n弱/强类型，指的是是否允许不兼容的类型进行运算。\r\n```\r\n\r\n比如在Javascript中，“4”-3的结果是数字1，这里字符串和数字做运算了。在强类型的语言中时不可以做这样的计算的。要在强类型中实现这样的表达式，就需要做重载，简单的如函数重载，就是一个函数可以有不同类型的，不同个数的参数，但是函数名一样，运算符重载，和函数重载的思想一样，只是运算符的参数位置比函数的参数灵活。总之，强类型语言不允许两个不兼容的类型之间运算，弱类型的语言允许不兼容的类型之间运算。\r\n\r\n**参考资料**\r\n\r\n[1] [强类型 JavaScript 的解决方案 by 阮一峰](http://www.ruanyifeng.com/blog/2015/02/strong-typing-javascript.html)"}}
{"actor":{"display_login":"muwenzi"}}