JS - 1
JS - 1
Introduction
— JavaScript is used to add functionality on our website or webapps. This makes the website usable. JavaScript is
a programming language that can run in web browsers and other environments. It can be used to create
dynamic and interactive web pages, as well as applications, games, and more. JavaScript is one of the most
popular and widely used languages in the world.
Features of JavaScript
1. It is interpreted, meaning it does not need to be compiled before running.
2. It supports first-class functions, meaning functions can be treated as values and passed as arguments or
returned from other functions.
3. It is prototype-based, meaning objects can inherit properties and methods from other objects without using
classes.
5. It is dynamic, meaning it can change the type and structure of variables and objects at runtime.
— We can use Ctrl + L to clear the console in Windows and for Mac it's cmd + K. We can also use up and down
arrow keys to access the previous inputs.
2. const: It is used to create constant values of any variable which can't be reassigned.
const name="narayan";
3. var: This is the old syntax of declaring variables in JS. It's use was replaced by let keyword in 2015. It's a
little bit different in comparison to JS.
JavaScript Page 1
little bit different in comparison to JS.
Variables in JS
— Variable is a container which is used to store data into it or we can say it is the name of a storage location. We
don't need to specify the datatype with variable initialization, because JS automatically detects the type of
variable.
a=10
b=5
age=23
name="narayan"
— Declaring variables without keywords is not recommended in JS.
Datatypes in JS
— There are 7 primitive datatypes in JS which are Number, Boolean, String, Undefined, Null, bigint (not much
used) and Symbol (not much used). We can use typeof to know the datatype of any variable.
typeof name
Numbers in JS
— All integers and floating numbers are considered as numbers in JS. There is a limit for size of numbers in JS
and if the number crosses the size limit then, JS will automatically store the nearest value instead of inputted
number which will be within the limits of JS.
Operator precedence in JS
— This is the general order of solving any expression in JavaScript. BPMDRAS means Bracket > Power >
Multiplication > Division > Remainder > Addition > Subtraction
— If there are multiple power operators present in any statement then evaluation of power operators will be
done from right to left in JavaScript.
Operators in JS
— There are 5 basic types of operators in JS.
4. Comparison: Used to compare two values ( <, >, ==, <=, >=, != ). We can compare a number to string
with (==). It will only compare the value but not the type. Whereas ( === ) will compare both value and
type of the variables.
JavaScript Page 2
type of the variables.
— 'a' will have lesser unicode value than 'b', 'c' have more unicode value than 'b' but less unicode value when
compared with 'd'. This cycle is valid for all uppercase and lowercase alphabets.
Identifier Rules
— All JavaScript variables must be identified with unique names (identifiers)
1. Names can contain letters, digits, underscores, and dollar signs (no space).
Boolean in JS
— It is used to represent a true or false value.
let age=23;
What is TypeScript
— It is developed by Mircosoft and now it has been adapted by many companies. TypeScript is an extended and
strict version of JavaScript. Where JavaScript is dynamic typed language but TypeScript is static typed
language.
let a;
— Whereas the null value represents the intentional absence of any object value. It is to be explicitly assigned.
JavaScript Page 3