Javascript Notes5
Javascript Notes5
geeksforgeeks
Courses
Tutorials
HTML/CSS
JavaScript
Sign In
GfG 160
Share Your Experiences
JavaScript Tutorial
JavaScript Basics
Introduction to JavaScript
JavaScript Versions
How to Add JavaScript in HTML Document?
JavaScript Syntax
JavaScript Output
JavaScript Comments
JS Variables & Datatypes
JS Operators
JS Statements
JS Loops
JS Perfomance & Debugging
JS Object
JS Function
JS Array
JS String
JS Numbers
JS Math
JS Map
JS Set
JS Objects
JS Advance
JavaScript Exercises
Full Stack DevelopmentCourse
JavaScript Syntax
Last Updated : 12 Aug, 2024
JavaScript syntax refers to the rules and conventions dictating how code is
structured and arranged within the JavaScript programming language. This includes
statements, expressions, variables, functions, operators, and control flow
constructs.
Syntax
// Variable declaration
let c, d, e;
Table of Content
JavaScript Literals
JavaScript Variables
JavaScript Operators
JavaScript Expressions
JavaScript Keywords
JavaScript Comments
JavaScript Data Types
JavaScript Functions
JavaScript Identifiers
JavaScript Literals
Syntax Rules for the JavaScript fixed values are:
let num1 = 50
let num2 = 50.05
console.log(num1)
console.log(num2)
console.log(str1)
console.log(str2)
Output
50
50.05
Geek
Geeks
JavaScript Variables
A JavaScript variable is the simple name of the storage location where data is
stored. There are two types of variables in JavaScript which are listed below:
// Function definition
function MyFunction() {
// Function call
MyFunction();
Output:
Apple
45
JavaScript Operators
JavaScript operators are symbols that are used to compute the value or in other
words, we can perform operations on operands. Arithmetic operators ( +, -, *, / )
are used to compute the value, and Assignment operators ( =, +=, %= ) are used to
assign the values to variables.
// Variable Declarations
let x, y, sum;
Output
26
JavaScript Expressions
Javascript Expression is the combination of values, operators, and variables. It is
used to compute the values.
// Variable Declarations
let x, num, sum;
Output
10
50
JavaScript Keywords
The keywords are the reserved words that have special meanings in JavaScript.
// Variable Declarations
let x, num, sum;
Output
50
JavaScript Data Types
JavaScript provides different datatypes to hold different values on variables.
JavaScript is a dynamic programming language, which means do not need to specify
the type of variable. There are two types of data types in JavaScript.
Syntax:
// Function definition
function func() {
// Declare a variable
let num = 45;
// Display the result
console.log(num);
}
// Function call
func();
Output
45
JavaScript Identifiers
JavaScript Identifiers are names used to name variables and keywords and functions.
A letter(A-Z or a-z)
A dollar sign($)
A underscore(_)
Note: Numbers are not allowed as a first character in JavaScript Identifiers.
Example: Both the variables firstName and firstname are different from each other.
console.log(firstName);
console.log(firstname);
Output
Geek
100
JavaScript Camel Case
In JavaScript Camel case is preferred to name a identifier.
Example:
let firstName
let lastName
JavaScript Character Set
A unicode character set is used in JavaScript. A unicode covers the characters,
punctuations and symbols.
We have a complete article on character sets. Click here to read Charsets article.
// Code to be executed
<script>
</script>
Master DSA with JavaScript in just 90 days. Explore core DSA concepts, refine your
coding skills, and tackle real-world challenges. Take on the Three 90 Challenge—
complete 90% of the course in 90 days and earn a 90% refund as a reward for your
commitment!
Comment
More info