Home >Web Front-end >Front-end Q&A >What is the difference between c++ and javascript
Differences: 1. C is a static language, while javascript is a dynamic language; 2. C is a compiled language, while javascript is an interpreted language; 3. C has pointers, but javascript has no pointers; 4. javascript is a functional programming language, C is not.
The operating environment of this tutorial: windows7 system, javascript1.8.5&&C version 17, Dell G3 computer.
1. C is a static language and js is a dynamic language.
The differences are as follows:
Static language:
Type detection can also be done when not executing, and detection can be done to a certain extent There are some logical errors. But too many declarations make the program redundant.
When you start writing code, you must consider what types of variables and calculations should be, which is conducive to writing good, high-availability programs.
is useful for compiler prompts and also for understanding the code.
Problem: Insufficient flexibility, and it is impossible to write programs without defining types.
Dynamic language:
The biggest advantage is the simplicity of the code.
Very flexible.
Problem: The running speed is relatively slow and type checking is required. The biggest disadvantage is that errors cannot be detected without execution.
2. C is a compiled language and js is an interpreted language.
C compilation process: Preprocessing->Compilation Optimization->Assembly->Link.
Parsing mechanism of Js: preprocessing (segmented reading code preprocessing) ->Explanation and execution
3. C has pointers, js has no pointers.
In C assignment, all basic types are copied directly, and custom types can choose to perform deep copy (copy) or shallow copy (reference) because of the existence of pointers. In js, all basic type assignments are copies, and all other type assignments are references.
4. JS is a functional programming language, C is not.
Js treats functions as objects, which can be used as input parameters and output values of functions (higher-order functions).
C If you want to use a function as an input parameter of other functions, that is, to implement a higher-order function, you must pass a function pointer (often one more (void *) type parameter must be passed as the parameter of the function) ).
5. The inheritance of C is based on classes, and the inheritance of js is based on prototypes
In C, inheritance is carried out through classes. It is more in line with people’s intuitive thinking. At the same time, after a class is generated, it cannot be modified unless its definition is modified. (Ruby's inheritance based on open classes can append the content of the class arbitrarily after definition)
In js, inheritance is carried out through the prototype chain. It is also possible to modify the prototype chain after definition. At the same time, you can also modify the prototype chain of the built-in type to extend the built-in type (use with caution, monkey patching may cause the built-in object to be significantly modified and produce unpredictable behavior).
[Related recommendations: javascript learning tutorial]
The above is the detailed content of What is the difference between c++ and javascript. For more information, please follow other related articles on the PHP Chinese website!