JavaScript Syntax
JavaScript is a dynamic and lightweight computer programming language. It is used to generate dynamic client-side pages. It is a cross-platform, open-source language.
Syntax
JavaScript syntax is the collection of principles that govern how JavaScript programs are built:
// Variable declaration
var x;
// Assign value to the variable
x = 6;
JavaScript syntax is the collection of principles that define a properly constructed JavaScript program. A JavaScript is made up of JavaScript statements that are inserted within the <script></script> HTML elements on a web page, or in an external JavaScript file with the .js extension.
JavaScript Variables
A JavaScript variable is just the name of the storage place where data will be kept. Variables in JavaScript are classified into two categories, which are listed below:
- Local variables: Declare a variable inside the scope of a block.
- Global variables: Declare a variable outside of a function or with the help of a window object.
JavaScript Operator
JavaScript operators are symbols that can be used to compute values or to perform operations on operands. Arithmetic operators (+, -, *, /) are used to compute values, whereas assignment operators (=, +=, %=) are used to assign values to variables.
JavaScript Expression
Expressions are made up of values, operators, and variables. It's used to calculate the values.
JavaScript Keyword
In JavaScript, keywords are reserved words with special meaning.
JavaScript Comments
The JavaScript compiler ignores the comments. It improves the readability of the code. It includes code recommendations, information, and warnings. Anything typed after double slashes // (single line comment) or between /* and */ (multi-line comment) is considered as a comment by the JavaScript compiler and ignored.
JavaScript Data Types
JavaScript supports many data types for storing distinct values on variables. Because JavaScript is a dynamic programming language, the type of variable does not need to be specified.
In JavaScript, there are two kinds of data types.
- Primitive data type
- Non-primitive (reference) data type
JavaScript Functions
JavaScript functions are chunks of code that are used to accomplish certain activities. When anything calls a JavaScript function, it gets executed. It invokes the method several times, making it reusable.