Javascript String.prototype unexpected token [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Apologies if this has been asked before but I couldn't find this specific issue.
I've been tasked with analysing a bit of highly obfuscated, and malicious, JS code. I'm trying to get it to run in a VM at the minute just to see exactly what it's up to but I'm getting a syntax error on the first line.
function String.prototype.x(){...
From Chrome's dev console:
Uncaught SyntaxError: Unexpected token .
The red squiggly line shows that the error is being thrown at the first dot (between String and prototype). To be honest, I don't know enough about JS to figure it out but I'm sure one of you lovely lot will know the answer. Why's it thrown and what can I do to fix it?

String is already a class (function with the inbuilt prototype methods) in JS , in order to create methods in its prototype chain you have use as below
String.prototype.reverse = function(){
return this.split('').reverse().join()
}
"hello".reverse() // olleh

Related

Why Node.js cannot run my JavaScript code in the terminal? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Can anyone please tell me why my javascript code cannot be executed? What is Uncaught SyntaxError: Unexpected Identifier?
You have a > before your text cursor. This means that you're already in Node.
Right now, what's happening is you're telling Node to run the following JavaScript:
node index.js
which, of course, is not valid JavaScript.
You need to exit Node so that the standard terminal is displayed, such as cmd or powershell (press Control-C a couple times)
Then you can type in node index.js. If you're in the same directory as the index.js file, it'll execute.

The nesting problem with “+=” (javascript) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Why is the result of JS -3?
a in JS does not seem to change with subsequent assignments
c:
int a=3;
a+=a-=a*a;
result:
a=-12;
js:
var a=3;
a+=a-=a*a;
result:
a=-3;
C and JavaScript have different rules to handle such expressions.
Clang (and probably also GCC and other C compilers) triggers a warning:
1.c:5:7: warning: unsequenced modification and access to 'a' [-Wunsequenced]
a+=a-=a*a;
~~ ^
1 warning generated.
In plain English this says that one of the read operations will not get the initial value of a but the current value of a at the moment when that operation is executed.
The statement above is executed the same way as:
a-=a*a;
a+=a;
This is why the result in C is -12 but it could be -3 as well.
Avoid writing such expressions. Even when there is no ambiguity about how they are evaluated, they are difficult to read and understand by other developers. One of the other developers is an older version of you. The code is written once but it is read many times. Let the code be easy to read an understand.

javascript/jquery syntax differences, declaring new a variable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
My code in javascript causes an error at the following line:
var tries:int=GetCallAttemptCount();
The error message says Error in Script Unexpected token : , Line 3
Line 3 is where the error appears. The script was originally in jquery, so I wonder is there a difference in how a variable is declared in Javascript and Jquery?
I'm computer literate, but I am a beginner with Javascript.
Thanks all, Adam
That's not javascript, this looks like typescript, in JS:
var tries = GetCallAttemptCount();

What is correct syntax for Jquery done()? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have the following syntax:
And am receiving the following error on line 6:
Uncaught SyntaxError: Unexpected token {
I read the api docs on done() and I can't see what I am doing wrong here.
$.post(path).done(funtion(data) { ....
^----notice any missing characters here, a "c" perhaps?
JS is trying to call a function called "funtion", which means that the { afterwards is illegal syntax. Since it parses out that syntax error first, it doesn't get to the point of being to able to tell you that "funtion" doesn't exist.
You wrote funtion instead of function.
$.post(path).done(function(data) { console.log(data) });

String and Uncaught Error: Syntax error, unrecognized expression [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have this code, where getURLParamter returns the value of a url parameter and I use that value to select on an input.
var urlParam = getURLParameter('a'),
selectedInput = $('input[id="custom-156[' + urlParam + ']"');
This has worked without problem through many rounds of cross-browser testing. However, there have been sporadic error reports from users including, finally, a co-worker. Chrome's console showed this error:
Uncaught Error: Syntax error, unrecognized expression: input[id="custom-156[1]"
My coworker uses the same model computer and the same version of Chrome. I don't have this error but he does. Why would this be and what is the cause of the error? I think it is a problem with the single double quotes within the pair of single quotes. What is a better way to write this?
There is no closing square bracket on the selector. you'll need
input[id="custom-156[' + urlParam + ']"]'
For the points ;)

Categories