Fundamentals - Part 1 Flashcards

1
Q

1 - Shortcut to Opening Console in Chrome?

2 - Shortcut for increasing font size in chrome console

A

1 - ctrl + shift + j

2 - ctrl +

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

alert “Hello world” in chrome

A

alert(“hello world!”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is JAVASCRIPT?

A

JAVASCRIPT IS A HIGH-LEVEL, OBJECT-ORIENTED, MULTI-PARADIGM PROGRAMMING LANGUAGE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What syntax we use to display (alert) the js output in chrome not in console

A

alert

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to display output data in console?

A

console.log

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a value in js? -
◉ ‘aman’ is a value or variable ?
◉ 23 is a value or variable ?
◉ how to display ‘aman’ in console?

A

◉ Smallest unit of the information is known as value
◉ ‘aman’ is a value
◉ 23 is a value
◉ to show the same in consol we need to do the following
console.log(“aman”);
console.log(23);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

◉ What is a variable?
◉ Syntax to assiagn a variable?
◉ What are the variable Name Convension for multiple words variable eg First Name?
◉ Is it correct to assign a variable with First Captial Letter ? Why?
◉ What type of Value are store in all capital letter variable like PI?
◉ How to write a descriptive variable naming?
◉ How to comment single line code
◉ How to comment multi line code

A

◉ variable is a box which store the value which we can use multiple times in a program

◉ to assign a variable in we use - let
eg.
let firstName = “aman”;
console.log(firstName);

◉ Name Variable with Multiple Words:-
let firstNamePerson  (Here 1st charater of 2nd and 3rd word must be Captial this type of naming is called camelcase )

or we can use underscore _

let first_name_person = “ravi”;

or $ sign can be used

let first$name$person = “aman”;

so these are the standard variable naming convensions

a variable name cannot start with a number like
let 3first = "aman"
  • also we can not name a variable with reserved js keyword
    eg.

let new=”aman”; (this is wrong because ‘new’ is a reserved js keyword )

  • ‘name’ is also a reserved keyword but we can use it. keeping in mind that this can create an error
- never start a variable name with Capital letters
eg.
let FirstName = "aman" (So here F is capital which is not illegal but not right way to do that)

because first charater uppercase type variable is reserved for the specific use case in js for eg. Object oriented programming

also note that variable in all uppercase like PI=”3.14” is reserved for the constant that we know will never change

 Use following standard convension
let firstName = "aman";
let first_name_person = "ravi";
let first$name$person = "firdosh";

Note: your variable name must be description which tell us what value it is holding eg.

-case1

let myFirstJob = 'programmer';
let myCurrentJob = 'teacher';

Case2

let job1 = 'programmer';
let job2 = 'teacher';

so we can see that case1 is more descriptve than case2

For Single Line Comment a code we need to use //
keyboard shortcut
Ctrl + /
uncomment again ctrl + /

For multiline comment
/*
Comments
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

◉ How many Data Types are there? Name them

◉ How many types of Primitive Data types are there

A

2 Types:-

◉ Objects - 
let me = {
name: 'jonas'
};
◉ Everything else - Primitive 
 let firstName = 'jonas';
let age= 30;

Now there are 7 Types of Primitive Data Types

1 - Numbers: Floating Numbers used for decimals and integers
let age = 30;
2- String: Sequence of characters -> Used for text
let firstName = 'Jonas';
3. Boolean: Logical type that can only be true or false � Used for taking decisions 
let fullAge = true;

4 - Undefined: Value taken by a variable that is not yet defined (‘empty value) eg.

let children;

5- Null: Also means ‘empty value

6- ES2015): Value that is unique and cannot be changed [Not useful for now]

7 - BigInt (ES2020): Larger integers than the Number type can hold

Note : JavaScript has dynamic typing: We do not have to manually define the data type of
the value stored in a variable. Instead, data types are determined automatically

we can use 'typeof' operator to check the variable type
let javaScriptIsFun = true;
console.log(javaScriptIsFun);
console.log(typeof true);
console.log(typeof javaScriptIsFun);
console.log(typeof 'aman');
console.log(typeof 23);

// undefined variable

let year;

console. log(year);
console. log(typeof year);

year = 1991;
console.log(typeof year);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

◉ What are the Difference between let, const, var variable ?

A

// let, const and var difference

let age = 30;
age = 31;

// value of let variable can be changed later in a program

// but the value of const can not be changed once assigned

const birthYear = 1991;

/* so now if we want to change value of birthYear then it will show an error
 birthYear = 1992;
 const birthYear;   this is not possible to declare an empty variable with const

Now question is which variable we should to declared

so usualy we should declare const variable if we know our variable need not to be changed in future

var is an old way of declaring variable which we will avoid now . It is pretty same as let

also we need to keep in mind the we can declare a variable without let, const or var but this is a terrible idea so we should not do that

firstName = “Aman”;

we must not do like this

*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

◉ What are the Basic Operators? Name them

A

//Math Operator - eg. calulate age

const ageAman = 2022 - 1992;
console.log(ageAman);
const ageMushtaq = 2022 - 1965;
console.log(ageMushtaq);

// To Show mutiple output with one console.log

console.log(ageAman, ageMushtaq);

// we have repeated 2022 twice so better to put the same in a variable

const currentYear = 2022;
const ageMahfooz = currentYear - 1970;
const ageNeha = currentYear - 1996;
console.log(ageMahfooz, ageNeha);

//other arithmetic operations

console.log(ageMahfooz * 2, ageNeha / 2, 2 ** 3);

// here 2 ** 3 means 2 to the power of 3 = 2 * 2 * 3

// to concatinate two variables we can use +

const firstName = 'aman';
const lastName = 'khan';

console.log(firstName + ‘ ‘ + lastName);

// assisnment operators

let x = 10 + 5; // x = 15

x += 10 // x = x +10 = 25 becuase in line 33 (last step) value of x become 15

console.log(x);

x *= 4 // x = x * 4 = 100 becuase in line 35 (lat step) value of x become 25

console.log(x);

x++ // x = x + 1 = 101

console.log(x);

x– // x = x-1 = 100
x– // x= x-1 = 99
console.log(x);

// comparasion operators
// it produce boolen values. lets check an example

console. log(ageMushtaq > ageAman); // result will be true
console. log(ageAman <= 18);// result should be false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

◉ operator precedence - which operator work first ?

A

maths operator excute before the comparisn operator

it also follow the bodmas rule from school

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

◉ Strings & template literals

A

with template literals, we can write a string in a more normal way, and then basically insert the variables directly into the string
and then they will simply be replaced. So basically a template literal can assemble multiple pieces into one final string.

// without template literals

const firstName = "Aman";
const job = "Digital Marketer";
const birthYear = 1992;
const currentYear = 2022;

const aman = “I’m “ + firstName + “, a “ + (currentYear - birthYear) + “ Years old “ + job;

console.log(aman);

// with template literals
// ` backticks will be find above tab
const amanNew = `I'm ${firstName}, a ${currentYear - birthYear} Years old ${job}`;
console.log(amanNew);

// we can write all string without variables also

console.log(This is just all string test);

// multiline strings
console.log(‘string with \n\
multiple \n\
lines’);

// multiline strings easy way using ` backticks

console.log(`this is
an
easy 
way 
to do that`);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

◉ Taking decision with if else statements

◉ What is syntax of if else statement?

A
const firstName = "Aman";
const age = 23;
const isOldEnough = age >= 18;
if (isOldEnough) {
    const eligible = `${firstName} is eligible for driving license 🚗`;
    console.log(eligible);
}
else {
    const nA = `${firstName} has ${18 - age} years left to be eligible for a driving license ❌`;
    console.log(nA);
}

// emoji on window 10 = window key + .

/* if else control structure

if()

{

}
else
{

}

*/

// program for 20th centry or 21st century

const birthYear = 2002;
let century;

if (birthYear <= 2000) {
century = “20th Century”;
}

else { century = “21st Century” }

console.log(century);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

◉ What is difference between conversion & coercion?

A
◉ // converting Data Type from String to number and others
/*
So type conversion is when we manually convert from one type to another.

One the other hand, type coercion is when JavaScript automatically converts types behind the scenes for us.

*/

◉ // Type Conversion

const inputYear = ‘1991’; // here 1991 is a string as this is in quotes

// so now if we want to do some calculate with inputYear then it will not work, let’s try

console.log(inputYear + 18); // if you are expecting result to be 2009 then you are wrong as here result will be concatenation 199118

// convert string to number
console.log(Number(inputYear), inputYear);  // here "N" will be upper case. So here first one is a number and second one is a string. So here we can notice that the original value of varibale has not change . Its still a string

console.log(Number(inputYear) + 18); // now result will be 2009

// we can not convert a something to number Which is imposible to convert.. example

const myName = 'Aman';
console.log(Number(myName));

// Above output will be NaN stands for Not a Number

// Now we will convert Number to string

console.log(String(23));
// here S will be upper case

// js can convert only to 2-3 types like number, string, boolen

// so this is a manual conversion but js do the same automatically which is called Coercion

◉ // type coercion

console. log(‘I am ‘ + 23 + ‘ years old’); // here coercion happens as 23 has been converted so string automatically
console. log(‘23’ - ‘10’ - 3); // this time result will be 10 which means js will convert 23 string to number . Please remeber is something is in blue then its number and if something is in yellow then it a string . here - minus operator behaves oppositly
console. log(‘23’ + ‘10’ + 3); // here output will be 23103 which means 23 is a string 10 is a string a 3 has been converted to string and all concetenate to give us 23103 result

// check for multiply and divide

console.log(‘23’ * ‘10’); // result will be 230 which means here 23 and 10 has been converted to numbers

let n = '1' + 1; // '11'
n = n - 1; //10
console.log(n); //result wil be 10  
// + convert number to string
// - * / converted string to number

console. log(2 + 3 + 4 + ‘5’); // = 95 .. as 2+3+5 = 9+ ‘5’ = 95
console. log(‘10’ - ‘4’ - ‘3’ - 2 + ‘5’); // ‘15’ string ‘10’-‘4’ = 6 -‘3’ =3-2 =1 +’5’ = ‘15’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

◉ What Falsy Value & Truthy Value?

◉ Tell 5 Falsy Value

A

◉ 5 falsy values: 0, empty string ‘’, undefined, null, NaN

◉ Everything else are the truthy value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
What will be the output for all the below code?
◉ console.log(Boolean(0));
◉ console.log(Boolean(undefined)); 
◉ console.log(Boolean('Jonas'));
◉ console.log(Boolean({})); 
◉ console.log(Boolean(''));
A
◉ console.log(Boolean(0)); 
◉ console.log(Boolean(undefined)); 
◉ console.log(Boolean('Jonas')); 
◉ console.log(Boolean({})); 
◉ console.log(Boolean(''));
17
Q
What will be the output of the following program?
const money = 0;  
if (money) 
{ console.log("Don't spend it all");}
else 
{ console.log("Get a Job!");}
A

// as we learnt above that boolean of 0 is false
so the if(money) returns the false
which means output will be
Get a Job!

18
Q
Output of the following program
const money1 = 5000;

if (money1) {
console.log(“Don’t spend it all”);
}

else {
console.log(“Get a Job!”);
}

A

Don’t spend it all

19
Q

output of the following program
let height;
if (height) {
console.log(Yah! Height is defined);
} else { console.log(Heigh is Undefined) };

A

Output: Heigh is Undefined

as value of height is not defined

20
Q
output of the following program?
let height1 = 5;
if (height1) {
    console.log(`Yah! Height is defined`);
} else { console.log(`Heigh is Undefined`) };
A

Output : Yah! Height is defined

21
Q

Why the output of following pogram is “Heigh is Undefined”?

let height1 = 0;
if (height1) {
    console.log(`Yah! Height is defined`);
} else { console.log(`Heigh is Undefined`) };
A

Because 0 is falsy value

22
Q

What is equality operator?

A

Suppose we want to check if two values are actually equal, instead of one being greater or less than the other. And for that we have different equality operators.

23
Q

◉ What is difference between = & == & === ?

◉ Which one is strict & Which one is loose equality operator?

A

◉ === operator is used to exact comparision
◉ === is strict equality operator which means is it will not do coercion (Converting data type)
◉ == is lose equality operator it will do coercion (Converting data type)

24
Q

Between = & == & === which one is assignment operator and which one is comparision operator

A

◉ = is an assignment operator

◉ == or === is a comparision operator

25
Q

Output of the following program and why?

const age = 18;
if (age === 18) console.log('You Just became an adult');
A

Output - ‘You Just became an adult’
Bcoz :-
const age = 18; // here data type of 18 is number
if (age === 18) // here also data type of 18 is number

26
Q

What if we do not include the curly brases { } for the statement in following program:- will be get result?

const age = 18;
if (age === 18) console.log('You Just became an adult');
A

Yes, bcoz { } is not mendatory if there is only if statement

27
Q

Output of the following program and why?

const age1 = 19;
if (age1 === 18) { console.log('You Just became an adult'); }
else { console.log("Your age is either more than 18 or less than 18"); }
A

Output: ‘Your age is either more than 18 or less than 18’

bcoz 18 and 19 are not equal

28
Q

Output of the following program- and why?

const age2 = '18';
if (age2 === 18) { console.log('You Just became an adult'); }
else { console.log("False, check you Data type"); }
A

Output: False, check you Data type

bcoz -
age2 = ‘18’; // data type is string
if (age2 === 18) // data type number

so when we are using === then both datatype must be same

29
Q

What is the syntax to check the datatype

A

typeof

30
Q

what function is used to prompt and output ?

A

prompt()