+ 3
[SOLVED] Is JavaScript exactly like C++?
Apart from the syntax differences, is all the logic that goes behind each element and data type the same? Do I have to re-declare a variable everywhere I use it in JScript? Are there compilers for JavaScript like C++ has? Just random questions which I haven’t been able to find reasonable answers to on the internet. Thanks for your time!
11 odpowiedzi
+ 5
JavaScript is an interpreted language, C++ a compiled one (and so JavaScript has no directives). That's a first huge difference.
Now JavaScript has no type to force a variable to be a number, a string, ... (unless you use TypeScript).
JavaScript is much more flexible than C++.
JavaScript is not multithreaded, unlike C++.
JavaScript is originally meant to be run in a browser, alongside with the DOM, so it comes with a ton of native DOM interactions.
You do not have to redeclare a variable once it has been declared unless you're out of scope. Be careful though, try using "let" and "const" instead of "var" unless you know what you're doing.
JavaScript can be interpreted by node, and such a node program can somewhat be "compiled" to an executable file, but what really happens there is that you simply get a package of node and your code mixed in.
There are also programs that compile towards JavaScript like TypeScript or ReactJS so that you can code in "improved" language.
+ 13
7Pineapple
Here is a good read about JavaScript
run-time environment and an analogy
with ( if you know ) Java
• What exactly is Node.js?
If you're wondering what exactly is Node.js, this helpful beginner's guide will get you started — https://www.freecodecamp.org/news/what-exactly-is-node-js-ae36e97449f5/
[ Edited: ] Gordon, Take a look at thisOne!😉🍻
+ 13
7Pineapple 👍
I'm glad if it helped you 😉
+ 11
7Pineapple Check this out,
• V8 Engine and Introduction to Node.js — https://www.webcodegeeks.com/javascript/node-js/v8-engine-introduction-nodejs/
+ 4
1. JavaScript and C++ are different. JavaScript has a lot of type conversion, for example:
1.1 reading 1:
https://code.sololearn.com/WYK8Yun7Y5nI/?ref=app (converted Number to string at line 17 for string concantention following method overloading of + operator).
2. It depends on the scope of your variable, and the keyword you used to declare variable.
2.1 reading 1: https://www.sololearn.com/post/39014/?ref=app in which there is https://code.sololearn.com/WdGAFeNRAe9M/?ref=app
2.2 reading 2: https://www.sololearn.com/post/45261/?ref=app in which there is http://davidshariff.com/blog/javascript-scope-chain-and-closures/
3. No, JavaScript is interpretational. Any modern browsers can run JavaScript program.
+ 3
It simply returns a boolean: true if clicked Ok and false otherwise.
Now you should really do one post one question, or things get really messed up and other people can't search for already answered questions.
+ 3
Dapper Mink thanks buddy
+ 3
7Pineapple thanks
+ 2
Thanks! This was much easier to understand than the previous one.
+ 1
If I use the confirm() function as
var option = confirm(‘some text’);
What value/string gets stored in option when the user selects Ok or Cancel.
+ 1
You can access a lot more low level resources with C++.