Explanation of the problem that JavaScript strict mode does not support octal

Explanation of the problem that JavaScript strict mode does not support octal

Regarding the issue that JavaScript strict mode does not support octal, first of all, we all know that JavaScript can express octal by adding 0 in front of the number.

as follows:

let i = 011;
console.log(i); // 9

But in strict mode, this approach breaks down:

"use strict";
let i = 011; // Uncaught SyntaxError: Octal literals are not allowed in strict mode.
console.log(i);


This means that octal is not supported in strict mode.

If you must use it, you can use a roundabout way to save the country:

Set the octal data as a string, then convert it through parseInt , and set the conversion base to octal.

"use strict";
let i = '011';
console.log(parseInt(i, 8)); // 9

This concludes the article on the issue of JavaScript strict mode not supporting octal. For more information on JavaScript strict mode, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JavaScript reference type examples detailed explanation [array, object, strict mode, etc.]
  • JS strict mode principle and usage example analysis
  • JavaScript strict mode (use strict) usage example analysis
  • Detailed explanation of JavaScript strict mode (including the difference between strict mode and non-strict mode)
  • Using Strict Mode in JavaScript
  • JavaScript variable hoisting and strict mode case analysis
  • A brief analysis of strict mode in JS
  • Summary of JS strict mode knowledge points
  • Detailed explanation of several directions of this in JavaScript strict mode
  • In-depth understanding of JavaScript strict mode (Strict Mode)

<<:  How to deploy Redis 6.x cluster through Docker

>>:  Thoughts on truncation of multi-line text with a "show more" button

Recommend

Apache Bench stress testing tool implementation principle and usage analysis

1: Throughput (Requests per second) A quantitativ...

A comprehensive understanding of Vue.js functional components

Table of contents Preface React Functional Compon...

How to install and deploy ftp image server in linux

Refer to the tutorial on setting up FTP server in...

Detailed example of SpringBoot+nginx to achieve resource upload function

Recently, I have been learning to use nginx to pl...

MySQL 8.0 user and role management principles and usage details

This article describes MySQL 8.0 user and role ma...

Summary of common commands for building ZooKeeper3.4 middleware under centos7

1. Download and decompress 1. Introduction to Zoo...

Vue implements graphic verification code login

This article example shares the specific code of ...

Summary of some common uses of refs in React

Table of contents What are Refs 1. String type Re...

In-depth analysis of MySQL indexes

Preface We know that index selection is the work ...

Two usages of iFrame tags in HTML

I have been working on a project recently - Budou...

Example code for implementing transparent gradient effects with CSS

The title images on Zhihu Discovery columns are g...

JavaScript to achieve the effect of clicking on the self-made menu

This article shares the specific code of JavaScri...

Detailed steps for setting up and configuring nis domain services on Centos8

Table of contents Introduction to NIS Network env...

How to generate PDF and download it in Vue front-end

Table of contents 1. Installation and introductio...