Javascript Syntax - Javascript tutorial
JavaScript Values
- The JavaScript syntax defines two types of values.
- Fixed values
- Variable values
- Fixed values are called Literals.
- Variable values are called Variables.
JavaScript Literals
- The following are the top two syntax guidelines for fixed values:
- 1. Numbers are written with or without decimals: 50.60, 5060
- 2. Strings are text, written within double or single quotes: "kaashiv infotech", 'kaashiv infotech'
JavaScript Variables
- Variables are used in computer languages to hold data values.
- JavaScript uses the keywords var, let and const to assign variables.
- An equal sign is used to assign values to variables.
- In this example, a is defined as a variable. Then, a is assigned the value 9.
Sample Code
Output
JavaScript Operators
- JavaScript uses arithmetic operators ( + - * / ) to compute values:
Sample Code
Output
Assigning JavaScript Variables
- JavaScript uses an assignment operator ( = ) to assign values to variables.
Sample Code
Output
JavaScript Expressions
- A set of values, variables, and operators combined to produce a value is called an expression.
- The computation is called an evaluation.
- For example, 5 * 5 evaluates to 25:
Output
JavaScript Keywords
- JavaScript keywords are used to identify actions to be performed.
- The let keyword tells the browser to create variables.
Output
JavaScript Comments
- Not all JavaScript statements are "executed".
- Code after double slashes // or between /* and */ is treated as a comment.
- Comments are ignored, and will not be executed.
Output
JavaScript is Case Sensitive
- All JavaScript identifiers are case sensitive.
- The variables lastName and lastname, are two different variables: