JavaScript Flashcards

1
Q

What is JavaScript

A

JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive.

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

How to open Developer Tools in Google Chrome ?

A

Keyboard Shortcut is :-

ctrl + shift + i

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

How to open console in Google Chrome ?

A

KeyBoard Shortcut is :-

ctrl + shift + j

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

Hot to write JS code from Google Chrome Console ?

A

Open Console window , & start typing JS code , hit enter to run code ?

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

How to Use alert in JS ?

A

alert + brackets + message to display in double quotes

alert(“Java Script is Fun”)

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

How to Declare variables in Java Script ?

A

We have 5 ways to Declare a Variable :-

  1. let age = 25;
  2. var countryName = ‘India’
  3. const year = 1998;
  4. let firstName; //undefined
  5. lastName; // Dynamic Typing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to write if Condition in Java Script ?

A

if keyword + condition in brackets + action statements in curly braces

let a = 10;

if (a==10)    alert('Java Script is FUN! ');
      or 
if (a==10){
   alert('Java Script is FUN! ');
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to write JS code inside a HTML Document ?

A

We have to use script element .

<
script>

<
/script>

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

How to get connected with google console ?

A

We have to use console.log method .

console.log(4+5+6+7+8)

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

How to load JavaScript file ?

A

We have to use script element under body of HTML Document .

<
script src=”script.js”><
/script>

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

How to load JavaScript file ?

A

We have to use script element under body of HTML Document .

<
script src=”script.js”><
/script>

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

What is an values in JavaScript ?

A

Value is an piece of Data.

It is the most fundamental unit of information in programing .

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

What is an values in JavaScript ?

A

Value is an piece of Data.

It is the most fundamental unit of information in programing .

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

How to Declare a variable in JavaScript ?

A

let fitstName= “Hemant”

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

How to Declare a variable in JavaScript ?

A

let fitstName= “Hemant”

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

How to pass an varaibale to Browser console ?

A
let firstName = "Hemant" ;
console.log(firstName) ;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What you include in Variable name ,according to naming convention in JvaScript ?

A

The variable name only contains ,letters,numbers,undercore & dollar

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

By which JavaScript variable starts with,according to conventions ?

A

JavaScript variables only starts with

lowercase letters,underscore or Dollar ?

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

How many Data Types are in JavaScript ?

A

Two Types :-

Primitifve & Objects

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

What are the Primitive Data Types in JavaScript ?

A

We have total Severn Data Types in JavaScript ?

  1. Number - let age=23;
  2. String - let firstName = “Hemant”;
  3. Boolean - isMale = true
  4. Undefined - let children;
  5. Null
  6. Symbol
  7. BigInt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is dynamic typing in JavaScript ?

A

It means automatic detection of data type
We dont have to manually define the data type,data types are determined automatically by JavaSript when it detects the value.
firstName = “Hemant”
JS automatically consider this as string data type.

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

How to know the type of value by chrome console ?

A

console. log(typeof true)

console. log(typeof javaScriptIsFun)

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

How to Declare undefined variable ?

A

let year;

24
Q

What term is called when we resign a variable ?

A

reassigning a variable is called mutation of variable or variable is mutated.

25
Q

What is mutation in JavaScriptt

A

Re-Assighning a variable

26
Q

What is mutation in JavaScriptt

A
Re-Assighning a variable
let age = 30;
age = 31 ;
27
Q

How to Declare Constant in JavaScript ?

A
const birthYear = 1991;
Here variable initialization is is mandatory ,without this JS gives error.
28
Q

What are immutable variables in JavasScript ?

A
Constant variables are immutable variables,whose value did not change in Program.
const  birthYear = 1990
29
Q

What are mutable variables in JavaScript ?

A
Variables  whose value is able to modified in program
let age = 31,
or we can say that varibles declared as , 
let age = 24;
var gender = "M"
firstName = "Hemant"  //dynamic typing
30
Q

What if we dont assighn a value to constant variable while declaring

A

Console gives Syntax Error: Missing initializer in const declaration .

31
Q

What is Variable Mutation ?

A

Reassigning value to variable is called Variable Mutation.

32
Q

What is a Difference Between , declaring a variable with let & var ?

A

let variable cant redeclared

var variable canbe redeclared

33
Q

How many Operators are in JavaScript ?

A

We have 5 type of operators in JavaSscript

  1. typeof operator
  2. Math operator + - * / **
  3. Assighnment Operators.
  4. comparison operator > < >= <= ==
  5. Logical Operators - && , || , !
34
Q

How to log multiple values to console ?

A
const ageSundy = 2022 - 1979 ;
const agePinky = 2022 - 1985 ;
console.log(ageSundy,agePinky)
35
Q

How to do calculation in console log ?

A
const ageHemsnt = 41;
console.log(ageHemsnt*2,ageHemsnt/2,2 ** 3)
36
Q

How to write exponent in JavaScript ?

A
console.log(2 ** 3)
// 2 raise to the power of three.
37
Q

How to concatenate two Strings ?

A

By using add math operator
const firstName = “Hemant “
const lastName = “Kumar”
console.log(firstName+lastName)

38
Q

What do you mean by evaluation sequence of Operators ?

A

It is called Operator Precedence,means priority of evaluating the operators, which one is evaluated first
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

39
Q

What is MDN

A

Mozilla Development Network

40
Q

How can we Concatenate string with variables ?

A

We may use add operator , but best way is to use Template Literals .

const firstName = "Hemant"
const job = "IT Professional"
const birthYear = 1979
const year = 2022
//Using  Math Operator
let hemant = "I'm " + firstName + ' a ' + (year - birthYear) + ' Year Old ' + job
console.log(hemant)
//Using Template literals
let userDetails = `"I'm  ${firstName}  a  ${year - birthYear}  Year Old {$ job}`
console.log(userDetails)
41
Q

What are Template Literals ?

A
Template Literal  can assemble multiple pieces into one final string.
const firstName = "Hemant"
const job = "IT Professional"
const birthYear = 1979
const year = 2022
console.log(hemant)
const hemantNew = `I'm ${firstName}, a ${year - birthYear} year old ${job}`
42
Q

How to write strings with Template Literals ?

A
const str1 = `Just a Regular String `
console.log(str1)
43
Q

How to write multiline strings ?

A

const str1 = String with Multiple Lines
console.log(str1)

44
Q

How to typecast to Number ?

A

We have to use Number() Function
const inputYear= ‘1991’;
console.log(Number(inputYear) + 18)

45
Q

What is NaN ?

A

It means Not an Number

46
Q

What is NaN ?

A

It means Not an Number

47
Q

How to type cast to String ?

A
We have to use string funnction .
const age=23;
console.log(typeof String(age))
48
Q

What is type conversion & type coercion ?

A

Type Coercion is an implicit or automatic type conversion , JavaScript is doing automatically for us.
Manual type casting is called Explicit type conversion

49
Q

What are falsy values and what they are ?

A

Values which considerd as boolean false is known as falsy values .

They are 5 falsy values :-
1, Zero, 0
2. empty string , ""
3. undefined
4.Null
5. NaN

Values other than this are True Values

50
Q

Give example of undefined variable ?

A

let height;
if(height) console.log(“Height is Defined”)
else console.log(“Height is not Defined”)

51
Q

What are Equality operators in JavaScript ?

A

We have 2 types of Equality Operators :-

  1. Strict Equality Operator === no typeconversion
  2. Loose Equality Operator == implicit type casting done by JavaScript
52
Q

How to get input from Browser ?

A
We have to use prompt() function.
const favourite = prompt("What is your Favourite number : -")
53
Q

How to display variable in alert() Function ?

A
We have to use Template Literals in alert() Function  :-
const favourite = prompt("What is your Favourite number : -")
alert(`Number Entered by you is ${favourite}`)
54
Q

What is Different Operator in JavaScript ?

A

Opposite of Equality operator is called Different Operator.They are of 2 types.

  1. Loose Different Operator - !=
  2. Strict defferent operator - !==
55
Q

Give an Example of logical operators ?

A
const hasDrivingLicense = true;
const hasGoodVision = true;
const isTired = true;
if (hasDrivingLicense && hasGoodVision || !isTired){
    console.log('Sarah is able to drive')
}else{
    console.log('Someone else should Drive')
}
56
Q

What is the term which converts one datype to other ?

A
The term is  called typecasting, it is of two ,types  :-
1. Implicit typecasting or type coercion - done automatically by JS
firstName = "Hemant" + 22; // here number 22 is tycasted to string & assigned as string to variable firstName automatically by Java Script
2. Explicit typecasting - It is Manual typecasting, done by Developer itself
let year = String(1991) // here number 1991 is typecast to string & assigned to variable year
57
Q

How to create Java Script File ?

A

We have to follow 3 Steps :-
Step 1 : Open any text editor ,
Step 2: Create a New file,
Step 3: Now save this file as script.js