JavaScript Flashcards
What is JavaScript
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 to open Developer Tools in Google Chrome ?
Keyboard Shortcut is :-
ctrl + shift + i
How to open console in Google Chrome ?
KeyBoard Shortcut is :-
ctrl + shift + j
Hot to write JS code from Google Chrome Console ?
Open Console window , & start typing JS code , hit enter to run code ?
How to Use alert in JS ?
alert + brackets + message to display in double quotes
alert(“Java Script is Fun”)
How to Declare variables in Java Script ?
We have 5 ways to Declare a Variable :-
- let age = 25;
- var countryName = ‘India’
- const year = 1998;
- let firstName; //undefined
- lastName; // Dynamic Typing
How to write if Condition in Java Script ?
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 to write JS code inside a HTML Document ?
We have to use script element .
<
script>
<
/script>
How to get connected with google console ?
We have to use console.log method .
console.log(4+5+6+7+8)
How to load JavaScript file ?
We have to use script element under body of HTML Document .
<
script src=”script.js”><
/script>
How to load JavaScript file ?
We have to use script element under body of HTML Document .
<
script src=”script.js”><
/script>
What is an values in JavaScript ?
Value is an piece of Data.
It is the most fundamental unit of information in programing .
What is an values in JavaScript ?
Value is an piece of Data.
It is the most fundamental unit of information in programing .
How to Declare a variable in JavaScript ?
let fitstName= “Hemant”
How to Declare a variable in JavaScript ?
let fitstName= “Hemant”
How to pass an varaibale to Browser console ?
let firstName = "Hemant" ; console.log(firstName) ;
What you include in Variable name ,according to naming convention in JvaScript ?
The variable name only contains ,letters,numbers,undercore & dollar
By which JavaScript variable starts with,according to conventions ?
JavaScript variables only starts with
lowercase letters,underscore or Dollar ?
How many Data Types are in JavaScript ?
Two Types :-
Primitifve & Objects
What are the Primitive Data Types in JavaScript ?
We have total Severn Data Types in JavaScript ?
- Number - let age=23;
- String - let firstName = “Hemant”;
- Boolean - isMale = true
- Undefined - let children;
- Null
- Symbol
- BigInt
What is dynamic typing in JavaScript ?
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 to know the type of value by chrome console ?
console. log(typeof true)
console. log(typeof javaScriptIsFun)
How to Declare undefined variable ?
let year;
What term is called when we resign a variable ?
reassigning a variable is called mutation of variable or variable is mutated.
What is mutation in JavaScriptt
Re-Assighning a variable
What is mutation in JavaScriptt
Re-Assighning a variable let age = 30; age = 31 ;
How to Declare Constant in JavaScript ?
const birthYear = 1991; Here variable initialization is is mandatory ,without this JS gives error.
What are immutable variables in JavasScript ?
Constant variables are immutable variables,whose value did not change in Program. const birthYear = 1990
What are mutable variables in JavaScript ?
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
What if we dont assighn a value to constant variable while declaring
Console gives Syntax Error: Missing initializer in const declaration .
What is Variable Mutation ?
Reassigning value to variable is called Variable Mutation.
What is a Difference Between , declaring a variable with let & var ?
let variable cant redeclared
var variable canbe redeclared
How many Operators are in JavaScript ?
We have 5 type of operators in JavaSscript
- typeof operator
- Math operator + - * / **
- Assighnment Operators.
- comparison operator > < >= <= ==
- Logical Operators - && , || , !
How to log multiple values to console ?
const ageSundy = 2022 - 1979 ; const agePinky = 2022 - 1985 ; console.log(ageSundy,agePinky)
How to do calculation in console log ?
const ageHemsnt = 41; console.log(ageHemsnt*2,ageHemsnt/2,2 ** 3)
How to write exponent in JavaScript ?
console.log(2 ** 3) // 2 raise to the power of three.
How to concatenate two Strings ?
By using add math operator
const firstName = “Hemant “
const lastName = “Kumar”
console.log(firstName+lastName)
What do you mean by evaluation sequence of Operators ?
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
What is MDN
Mozilla Development Network
How can we Concatenate string with variables ?
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)
What are Template Literals ?
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}`
How to write strings with Template Literals ?
const str1 = `Just a Regular String ` console.log(str1)
How to write multiline strings ?
const str1 = String
with
Multiple Lines
console.log(str1)
How to typecast to Number ?
We have to use Number() Function
const inputYear= ‘1991’;
console.log(Number(inputYear) + 18)
What is NaN ?
It means Not an Number
What is NaN ?
It means Not an Number
How to type cast to String ?
We have to use string funnction . const age=23; console.log(typeof String(age))
What is type conversion & type coercion ?
Type Coercion is an implicit or automatic type conversion , JavaScript is doing automatically for us.
Manual type casting is called Explicit type conversion
What are falsy values and what they are ?
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
Give example of undefined variable ?
let height;
if(height) console.log(“Height is Defined”)
else console.log(“Height is not Defined”)
What are Equality operators in JavaScript ?
We have 2 types of Equality Operators :-
- Strict Equality Operator === no typeconversion
- Loose Equality Operator == implicit type casting done by JavaScript
How to get input from Browser ?
We have to use prompt() function. const favourite = prompt("What is your Favourite number : -")
How to display variable in alert() Function ?
We have to use Template Literals in alert() Function :- const favourite = prompt("What is your Favourite number : -") alert(`Number Entered by you is ${favourite}`)
What is Different Operator in JavaScript ?
Opposite of Equality operator is called Different Operator.They are of 2 types.
- Loose Different Operator - !=
- Strict defferent operator - !==
Give an Example of logical operators ?
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') }
What is the term which converts one datype to other ?
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
How to create Java Script File ?
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