Skip to content

第 116 期(W3C 标准-JavaScript):atob & btoa —— base64 的解码编码 #119

Open

Description

@wingmeng

atob() 和 btoa() 方法用于对字符串进行 base64 解码和编码,其中:

  • atob() 用于解码,例如:window.atob('aGVsbG8gd29ybGQ=')
  • btoa() 用于编码,例如:window.btoa('hello world')

它们 API 的命名颇具喜感,这里要注意 不要 把 atob 望文生义成 Any to Base64。可以这样来记忆:
字母 A 排在 字母 B 前面,所以 A 要比 B “高级”,A 就代表高级的 Base64,而 B 则代表普通的字符串。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions