What is the percentage (%) in JavaScript?

In many codes, I saw % . Can you explain to me his purpose or what does she do?

PS: % ignored from Google search, so I could not find it on Google.

Edit: I know the operand in math is 13 % 10 = 3 , but what I saw is like return %foo .

+7
source share
1 answer

Based on the link provided in the comments, the % symbol is apparently used in some JavaScript V8 engine to indicate the C ++ runtime method that will be executed when parsing the JavaScript source code.

For example, a string in string.js :

 return %StringBuilderConcat(parts, len + 1, ""); 

When it encounters a parser, the StringBuilderConcat method will be executed. You can find a list of the execution methods available for V8 JavaScript files in runtime.h (note I have no experience with C ++, so for all I know, this has nothing to do with the StringBuilderConcat method specified in string. js, but I think this is the same):

 #define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \ /* Property access */ \ F(GetProperty, 2, 1) \ F(KeyedGetProperty, 2, 1) \ /* ... */ F(StringBuilderConcat, 3, 1) \ /* ... */ 

As already mentioned, return %foo throw a SyntaxError in JavaScript.

+9
source

All Articles