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

Use IISMonitor to monitor web pages and automatically restart IIS

Table of contents 1. Tool Introduction 2. Workflo...

How to elegantly implement WeChat authorized login in Vue3 project

Table of contents Preface Prepare Implementation ...

Summarize the common application problems of XHTML code

<br />For some time, I found that many peopl...

VMware kali virtual machine environment configuration method

1|0 Compile the kernel (1) Run the uname -r comma...

How to use physics engine joints in CocosCreator

Table of contents mousejoint mouse joint distance...

Summary of Vue's common APIs and advanced APIs

Table of contents nextTick Mixins $forceUpdate se...

How to use CSS attribute selectors to splice HTML DNA

CSS attribute selectors are amazing. They can hel...

Web componentd component internal event callback and pain point analysis

Table of contents Written in front What exactly i...

Several methods of implementing two fixed columns and one adaptive column in CSS

This article introduces several methods of implem...

Mini Program natively implements left-slide drawer menu

Table of contents WXS Response Event Plan A Page ...

The basic principles and detailed usage of viewport

1. Overview of viewport Mobile browsers usually r...