What is JavaScript?
JS is a programming language. We use it to give instructions to the computer.
lege
Col
a
Input (code) Computer Output
Apn
use console in any browser or just open one of your projects and use that
the code is not permanent, we can use the up & down arrow to bring back old code
Setting up VS Code
It is a free & popular code editor by Microsoft
lege
Col
pna
A we'll use the chrome developer tools console to write our code
but not for long terms as afterwards we will start to use js file
like we used for css
Our 1st JS Code
[Link] is used to log (print) a message to the console
lege
Col
[Link](“Apna College”); = [Link]("Apna College");
pna
A
(NO DECLARATION REQUIRED): Dynamically-typed Languge
Variables in JS
Variables are containers for data
e
(like in Java)
lleg
a Co
n
radius
14
Ap
memory
Variable Rules
Variable names are case sensitive; “a” & “A” is different.
lege
l
Only letters, digits, underscore( _ ) and $ is allowed. (not even space)
a Co
Only a letter, underscore( _ ) or $ should be 1st character.
Apn
Reserved words cannot be variable names.
undefined: we do not know what is in the variable
null: we know what is there in the variable
Declaration in Java::
let, const & var
var : Variable can be re-declared & updated. A global scope variable. (bekar h yeh)
lege
ol
let : Variable cannot be re-declared but can be updated. A block scope variable.
C
pna
A
const : Variable cannot be re-declared or updated. A block scope variable.
For Input:
let a=prompt("Enter a number :");
(Always takes input in the form of String)
Data Types in JS
(absence of object)
Primitive Types : Number, String, Boolean, Undefined, Null, BigInt, Symbol
g e
(long) (for symbols)
(Like JAVA) lle
a C o
object - A
p n
typeof(); - for type of variable
like dictionary in Python
student={ (key : value) age : 24, name : "Rahul", marks : 43};
To access value from key: [Link] / student["age"]
([Link] / obj["key"])
ge
String
ol le
a C
Number
Follow
Apn
Boolean
Let‘s Practice
Qs1. Create a const object called “product” to store information shown in the picture.
lege
Col
pna
A
Let‘s Practice
Qs2. Create a const object called “profile” to store information shown in the picture.
lege
Col
pna
A