示例代码:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>JavaScript字符串编解码</title>
</head>
<body>
<script>
var str = 'a';
//字符的 Unicode 编码
var unicode = str.charCodeAt(0);
console.log(unicode);
//字符解码
var strNew = String.fromCharCode(unicode);
console.log(strNew);
</script>
</body>
</html>