syntax-error interview questions
Top syntax-error frequently asked interview questions
When loading my page in Google Chrome, I get a vague error in the console:
Uncaught SyntaxError: Unexpected end of input
I have no idea what is causing it. How would I go about debugging this error?
Source: (StackOverflow)
This is weird. This is what happens at the JavaScript console in Chrome (version 42.0.2311.135, 64-bit).
> 0
< 0
> 00
< 0
> 0.0
< 0
> 00.0
X Uncaught > SyntaxError: Unexpected number
Firefox 37.0.2 does the same, although its error message is:
SyntaxError: missing ; before statement
There's probably some technical explanation regarding the way JavaScript parses numbers, and perhaps it can only happen when tinkering at the console prompt, but it still seems wrong.
Why does it do that?
Source: (StackOverflow)
When I tried the following code I get the error mentioned.
if(a==1)
int b =10;
But the following is syntactically correct
if(a==1)
{
int b = 10;
}
Why is this?
Source: (StackOverflow)
Herer is my CRONTAB file (Ubuntu 10.10):
57 1 * * 2-6 ET=`date --date 'yesterday'+%Y%m%d`;echo $ET
Even The syntax color indicate that something is wrong. and there is this error:
Subject: Cron <root> ET=`date --date 'yesterday' + (failed)
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
/bin/sh: Syntax error: EOF in backquote substitution
But I am not sure whats wrong. Thanks a lot!
Source: (StackOverflow)
I have an existing project that uses @Override
on methods that override interface methods, rather than superclass methods. I cannot alter this in code, but I would like Eclpse to stop complaining about the annotation, as I can still build with Maven.
How would I go about disabling this error?
Note: Due to project requirements, I need to compile for Java 1.5.
Source: (StackOverflow)
I've been using them forever, and I love them. To me they see cleaner and i can scan faster, but ever since I've been using them i've always had to put null
in the else conditions that don't have anything. Is there anyway around it? E.g.
condition ? x=true : null ;
basically, is there a way to do:
condition ? x=true;
Now it shows up as a syntax error...
FYI, here is some real example code:
!defaults.slideshowWidth ? defaults.slideshowWidth = obj.find('img').width()+'px' : null ;
Source: (StackOverflow)
Below query I'm executing in Ubuntu 12, MySQL 5.1 version and receiving error as mentioned:
CREATE TABLE mantis_config_table (
config_id VARCHAR(64) NOT NULL,
project_id INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL DEFAULT 0,
access_reqd INTEGER DEFAULT 0,
type INTEGER DEFAULT 90,
value LONGTEXT NOT NULL,
PRIMARY KEY (config_id, project_id, user_id)
) TYPE=MyISAM;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM' at line 9
Can anyone suggest what's wrong?
Source: (StackOverflow)
This question already has an answer here:
Why is Python giving me a syntax error at the simple print
statement on line 9?
import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = raw_input("What is the file name in which the hash resides? ")
wordlist = raw_input("What is your wordlist? (Enter the file name) ")
try:
hashdocument = open(hash_file,"r")
except IOError:
print "Invalid file." # Syntax error: invalid syntax
raw_input()
sys.exit()
else:
hash = hashdocument.readline()
hash = hash.replace("\n","")
The version is:
Python 3.2.2 (default, Sep 4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win
32
Source: (StackOverflow)
The following code raises a syntax error:
>>> for i in range(10):
... print i
... try:
... pass
... finally:
... continue
... print i
...
File "<stdin>", line 6
SyntaxError: 'continue' not supported inside 'finally' clause
Why isn't a continue
statement allowed inside a finally
clause?
P.S. This other code on the other hand has no issues:
>>> for i in range(10):
... print i
... try:
... pass
... finally:
... break
...
0
If it matters, I'm using Python 2.6.6.
Source: (StackOverflow)
I have been working on a small slideshow / public display for a client that uses HTML5 Rock's Slideshow code. I have run into a DOM Exception 12 - a syntax error that is supposedly related to CSS selectors - while monkeying around with it... but I can't trace it back to any changes I made in the code. I am thinking it might be something that was uncovered as I added features.
I have traced it down to this object (live version here):
var SlideShow = function(slides) {
this._slides = (slides || []).map(function(el, idx) {
return new Slide(el, idx);
});
var h = window.location.hash;
try {
this.current = h;
} catch (e) { /* squeltch */ }
this.current = (!this.current) ? "landing-slide" : this.current.replace('#', '');
if (!query('#' + this.current)) {
// if this happens is very likely that someone is coming from
// a link with the old permalink format, i.e. #slide24
alert('The format of the permalinks have recently changed. If you are coming ' +
'here from an old external link it\'s very likely you will land to the wrong slide');
this.current = "landing-slide";
}
var _t = this;
doc.addEventListener('keydown',
function(e) { _t.handleKeys(e); }, false);
doc.addEventListener('touchstart',
function(e) { _t.handleTouchStart(e); }, false);
doc.addEventListener('touchend',
function(e) { _t.handleTouchEnd(e); }, false);
window.addEventListener('popstate',
function(e) { if (e.state) { _t.go(e.state, true); } }, false);
};
Instantiation of SlideShow()
(line 521 in main.js):
var slideshow = new SlideShow(queryAll('.slide'));
Calling queryAll('.slide')
returns an array of all the slides with an class of .slide
. However, when passing queryAll('.slide')
as a parameter for instantiating SlideShow()
, it returns a DOM Exception 12
error.
Has anybody seen this before?
Source: (StackOverflow)
A friend wrote some code for me, and there was one file with a weird syntax error in it. After a bit of hunting, I narrowed it down to this section of code, which should reproduce the error:
var say = functіon(message) {
alert(message);
return message;
};
say(say("Goodbye!"));
When I run this, I see an error in the Internet Explorer console that says SCRIPT1004: Expected ';'
. I don't see a semicolon missing anywhere, and I can't image where it wants me to put one.
Where does it expect a semicolon and why does it expect a semicolon there?
Source: (StackOverflow)
In Firefox 3.5, I type this in the Firebug console :
false=={} // => evals to false
{}==false // syntax error
What is the explanation for this ?
Source: (StackOverflow)
I am getting this PHP error:
PHP Notice: Undefined offset: 1
Here is the PHP code that throws it:
$file_handle = fopen($path."/Summary/data.txt","r"); //open text file
$data = array(); // create new array map
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle); // read in each line
$parts = array_map('trim', explode(':', $line_of_text, 2));
// separates line_of_text by ':' trim strings for extra space
$data[$parts[0]] = $parts[1];
// map the resulting parts into array
//$results('NAME_BEFORE_:') = VALUE_AFTER_:
}
What does this error mean? What causes this error?
Source: (StackOverflow)
JavaScript programs can be checked for errors in IDEs or using online web apps but I'm looking for a way to detect syntax errors alone.
I've tried JSLint and JSHint and looked at their options but I haven't been able to find a combination that would exclude warnings and just shows the syntax errors.
How do I check JavaScript code for syntax errors only from the command line?
Source: (StackOverflow)
r'\'
in Python does not work as expected. Instead of returning a string with one character (a backslash) in it, it raises a SyntaxError. r"\"
does the same.
This is rather cumbersome if you have a list of Windows paths like these:
paths = [ r'\bla\foo\bar',
r'\bla\foo\bloh',
r'\buff',
r'\',
# ...
]
Is there a good reason why this literal is not accepted?
Source: (StackOverflow)