Why does one mistake in javascript make the whole script wrong | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Why does one mistake in javascript make the whole script wrong

18th Oct 2020, 1:19 PM
Astrav
Astrav - avatar
6 ответов
+ 4
I am not sure what right or wrong mean in this context. But a syntax error will cause the present script in execution to crash. Are you expecting something different? Did you know of any language whose interpreter forgives syntax errors?
18th Oct 2020, 1:29 PM
Ore
Ore - avatar
+ 4
Astron Daniel Did you ask this question because you were confused why JavaScript cannot be forgiving like HTML as Arsenic assumes. If so, I understand why you might think like that. But JavaScript is different in the sense that the program is divided into statement which are executed sequentially. Consider the following JS code that prompts a user for input and logs a modified version of the input. var text = prompt("Enter some text") console.log(">>>" + text + "<<<") Line 2 will be meaningless without line 1. So it makes sense for the program to stop execution(crash) if line 1 contains a syntax error. Like this var text := prompt("Enter some text") The program will crash because of the misplaced colon ':'
18th Oct 2020, 1:41 PM
Ore
Ore - avatar
+ 2
Because a mistake is not a mistake till the time it is not doing anything wrong.
18th Oct 2020, 1:20 PM
Arsenic
Arsenic - avatar
+ 2
Ore maybe he is used to mark up languages like HTML
18th Oct 2020, 1:30 PM
Arsenic
Arsenic - avatar
+ 1
Ore consider the following code on CSS .space{ color:#00ff11; background:#111; fontsize:30px;} As you can see fontsize is wrong because it is missing a "-" so it wont be executed but the rest will be executed. If it was for javascript the whole code would be wrong and nothing would be executed.
19th Oct 2020, 6:27 AM
Astrav
Astrav - avatar
+ 1
Astron Daniel CSS rules are cascaded. The effect of one rule is affected by the other rules. So I think CSS does not make a good example here. The whole stylesheet may not work because of a bad rule. .parent { display: flexes; flex-direction: column; flex-gap: .8em; justify-content: space-between; } .child { flex: 1 0 50px; } The entire style above is meaningless because of the first rule which can be corrected to display: flex; Magic? Hopefully not! Also considering your example, if it contained syntax error. It acts similarly to JS. .space { color: #00ff11 background: #111; font-size: 30px } The element will have a black (instead of green) text on white (instead of light gray) background because of the missing semicolon in line 2.
19th Oct 2020, 6:46 AM
Ore
Ore - avatar