Code Structure Of JavaScript | Fundamentals of JavaScript Programming Language | Part - 2
Code Structure Of JavaScript (js) :
Here is a list of some of the fundamentals of JavaScript that we discussed about in previous tutorial:
- JavaScript Statements
- JavaScript Semicolons
- JavaScript Whitespaces
- JavaScript Parenthesis
- JavaScript Identifiers
- JavaScript Indentation
- JavaScript Reserved Keyword
- JavaScript Case Sensitive
- JavaScript Comments
- JavaScript Camel Case
If you didn't read one of these, click here to read previous article of part-1 .
Here is a list of some of the fundamentals of JavaScript that you will learn about in this tutorial of Part - 2 :
- JavaScript Syntax
- JavaScript Values
- JavaScript Literals
- JavaScript Expression
- JavaScript Variables
- JavaScript Operators
- JavaScript Character Set
- JavaScript Data Types
- JavaScript Code Blocks
- JavaScript Line Length and Line Breaks
11. Syntax in JavaScript (js):
JavaScript syntax is the set of rules, how JavaScript programs are constructed.
// How to create variables:
var x;
let y;
// How to use variables:
x = 5;
y = 6;
let z = x + y;
12. Values in JavaScript (js):
The JavaScript syntax defines two types of values:
The JavaScript syntax defines two types of values:
- Fixed values
- Variable values
- Fixed values
- Variable values
Fixed values are called Literals.Variable values are called Variables.
13. Literals in JavaScript (js):
JavaScript Literals are constant values which can be a numeric, string, floating-point value, a boolean value or even an object that can be assigned to the variables that are called literals or constants.
Types of literals in javascript (js) :
There are four types of literals :-
- String literals
- Number literals
- Boolean literals
- Null literals.
1. String Literals: String literals are always surrounded by single quotes (') or double quotes (")
let tutorial = 'Best JavaScript Tutorials';
let tutorial = "Best JavaScript Tutorials";
2. Number Literals: Number literals can be written with or without decimal places. Number literals can be either positive numbers or negative numbers. If you do not specify a sign, then a positive number is assumed.
let tutorial = 'Best JavaScript Tutorials';
let tutorial = "Best JavaScript Tutorials";
3. Boolean Literals: Boolean literals can either be true or false. These values are special keywords in JavaScript and don't need quotes. Here are the two types of Boolean literals:
4. Null Literals : Null literals are a special literal value in JavaScript. A null represents the absence of a value.
let numOne = null;
3. Boolean Literals: Boolean literals can either be true or false. These values are special keywords in JavaScript and don't need quotes. Here are the two types of Boolean literals:
4. Null Literals : Null literals are a special literal value in JavaScript. A null represents the absence of a value.
let numOne = null;
14. Expression in JavaScript (js):
An expression is any valid unit of code which is a combination of values, variables, and operators that computes to a value. The computation is called an evaluation.
For example, 5 * 10 evaluates to 50:
14. Expression in JavaScript (js):
An expression is any valid unit of code which is a combination of values, variables, and operators that computes to a value. The computation is called an evaluation.
For example, 5 * 10 evaluates to 50:
let person = "John" + " " + "Doe";
let income = 23*2000;
let newIncome = income + 10960;
let person = "John" + " " + "Doe";
let income = 23*2000;
let newIncome = income + 10960;
15. Variables in JavaScript (js):
A variable is a container (storage area) which is used to store data values and it is also known as named containers.
- JavaScript uses the keywords var, let and const to declare variables.
- An equal sign is used to assign values to variables.
let personAge;
let personAge = 30;
In this example, personAge is defined as a variable. Then, personAge is assigned (given) the value 30
16. Operators in JavaScript (js):
JavaScript operators are symbols that are used to perform operations on operands (values and variables) which tell the JavaScript engine to perform some sort of actions.
let sum= 10+20;
JavaScript operators are symbols that are used to perform operations on operands (values and variables) which tell the JavaScript engine to perform some sort of actions.
let sum= 10+20;
Here, + is the arithmetic operator and = is the assignment operator. There are following types of operators in JavaScript:
- Arithmetic Operators
- Comparison (Relational) Operators
- Bitwise Operators
- Logical Operators
- Assignment Operators
- Special Operators
17. Character Set in JavaScript (js):
JavaScript programs are written using the Unicode character set. Unicode is a superset of ASCII and Latin-1 and supports virtually every written language currently used on the planet. ECMAScript 3 requires JavaScript implementations to support Unicode version 2.1 or later, and ECMAScript 5 requires implementations to support Unicode 3 or later.
18. Data Types in JavaScript (js):
A data type is a classification of data to hold different types of values which tells the compiler or interpreter how the programmer intends to use the data.
There are two types of data types in JavaScript.
A data type is a classification of data to hold different types of values which tells the compiler or interpreter how the programmer intends to use the data.
There are two types of data types in JavaScript.
- Primitive data type
- Non-primitive (reference) data type
- Primitive data type
- Non-primitive (reference) data type
JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc.
let courseName = "Best JavaScript Tutorials"; //holding strings
let courseNo = 2; //holding a number
JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc.
let courseName = "Best JavaScript Tutorials"; //holding strings
let courseNo = 2; //holding a number
19. Code Blocks in JavaScript (js):
A code block simply consists of grouped statements with curly braces { } .
JavaScript statements can be grouped together in code blocks, inside curly brackets {...}.
The purpose of code blocks is to define statements to be executed together.
function myFunction() {
document.getElementById("person1").innerHTML = "Hello Dolly!";
document.getElementById("person2").innerHTML = "How are you?";
}
20. Line Length and Line Breaks in JavaScript (js):
For best readability, programmers often like to avoid code lines longer than 80 characters.
If a JavaScript statement does not fit on one line, the best place to break it is after an operator:
document.getElementById("welcome").innerHTML =
"Hello JavaScript Programmers!";
Previous Post:
For best readability, programmers often like to avoid code lines longer than 80 characters.
If a JavaScript statement does not fit on one line, the best place to break it is after an operator:
document.getElementById("welcome").innerHTML =
"Hello JavaScript Programmers!";
Previous Post:
0 Response to Code Structure Of JavaScript | Fundamentals of JavaScript Programming Language | Part - 2
Post a Comment