JavaScript Flashcards

(55 cards)

1
Q

What are es6 and es7 in JS

A

Es stands for ECMAscriptn
And they are two versions or updates of js
Es6 is in 2015
Es7 is in 2016
Each one added different features

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

How do you connect your JS with your code ?

A

Script tag
Src
In the body at the end

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

How to use DOM functions to point to html elemets

A

document.getelementbyid
Getelementsbyclassname
Queryselector
Queryselectorall

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

What is $ used for in js

A

Allows you to embed variables inside a string , so changing variable within a static string

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

Explain destructuring objects(say the syntax)

A

It is a way to extract values from objects or arrays and assign them to variables using shorter syntax.

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

What type of data can you have in an object

A

Numerical
Objects
Array
String boolean
Null
Undefined

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

How to use destructuring when you have nstead objects?

A

Const{objectName:{key}}=big object name

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

What are the components of an object

A

Const object ={ Key:value, ———}
And const object can change values inside

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

How does destructuring work in array?

A

So as said we are initializing values in easier sytax
const [name]=array name, or [array]
Now name will point to the first element in the array
And you can add other variables after name to point to other values in the array in order

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

How can you shorten the syntax of an object inside a function and what do you call it

A

You do const object={ parameter1,parameter2,…..}
This will make the object have the parameter name as key and the passed value through the the value of that key.
call Object Property Shorthand

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

What is template literal

A

a feature added in es6 that allows you to imped variables in strings, concatenate strings, help with readability, and multi line string while using the backtick

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

What is for of loop and what is it’s syntax

A

A loop where you can iterate through stuff like strings are arrays easily
The syntax is for (let/const anyname of array name or string name)
{Do work here (the name you chose will point to each array element and you can do whatever you want, but it will not modify the array it self, so it will be a variable pointing to the array elements not referencing to the actual array}

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

What is ‘ called

A

Backtick

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

Why is backtick better than “ or single quotation

A

Because it is one of the template literature that allows text formatting happen like spaces and new lines.
Any thing you write inside will be written in the console like you wrote.
Without backtick you cannot use variables inside {}

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

How to do a new line in console log when using a “ or single

A

By \n

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

Talk about spread operator

A

Now when you make an array =array1
Array will now reference to it
But with spread operator you shallow copy the content of the array to a new array and you can modify stuff.
array=[…array1]
can also used with objects
you can merge, over ride, add new values or just simply copy , using spread operator

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

Does spread operator work to copy objects?

A

Yes
So …name
Means copy all the data inside

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

What is arrow function

A

A way to make a function but anonymously

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

What are the ways to make a function

A

unanimously:
const camelCase= function (){}
Or
Const camelCase= ()=>{}
normal:
function camelCase (parameters)

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

How to make a normal function in js

A

function name () {}

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

What is the implicit return feature in fucntions

A

When you have only one line in the function and you just write it without return or {} (only for arrow) not named functions it will consider it as return automatically

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

Explain this
const name = (food=something)=>{} and what do you call it

A

This means when you forget to pass a parameter your parameter will be automatically set to something, if you pass, it will be updated
Called default parameter

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

Explain includes() function

A

Will return true or false , will iterate through an array and check if it has that value or not

24
Q

What do you need to do imports and exports when working with js?

A

You need nodejs at least vs 12
Check node —version
And you name your files .mjs
M is for module
add type ‘module’ is your script tag and don’t forget to put .mjs in src

25
Does folders with package.JSON need to be named with .mjs
No, they already have module Like react So you can import and export without .mjs
26
Why do you use imports and exports
Assume you have multi js files and you have a set of data that you want to move to another file You export it from one and import it to another
27
What is a class
It has the properties (variables , functions) that describe a set of objects
28
What is an instance?
It is a instantiation of a class (عمل مثيل) where it has all the properties in that class
29
What are some needed stuff in the class?
Constructor You write Constructor(variables must be passed when making an object) {this.parameter=parameter;} . . . to print ex: print(){ console.log(this.x,this.y) }
30
How to make an instance or object
const name =new class (variables)
31
Can you export classes?
Yes by writing export and initializing the class normally (same as other stuff)
32
How to inhert classes in js
By using extends Class Name extends Parent { …. }
33
Can extended classes override original functions from parent
Yes and when calling the function it will be called, otherwise the parent function will be called
34
What does super function do and what is it’s syntax
Used in class inhertance It calls the constructor of the parent class within the extended class. You must always call it when doing a child constructor
35
Talk about promises
A promise represents a value (final result) is not immediately known, it waits for the asynchronous operation like fetching data to be over and the value will be known later . Used to handle asynchronous operations
36
Asynchronous functions are
Functions that don’t wait for tasks to happen like API calls or fetching data
37
Is JS async?
Yes
38
What happens when a promise is created
It promises that it will get back with a result ( the async operator will complete) either with success or reject So it does not promise a full success chance
39
Why are .then and .catch used for
After the result of operation is known, it uses them to handle the results Then for success Catch for error
40
What does await do
It pauses excution until promise value is known
41
Is promise a class?
Yes , and it has reject and resolve functions
42
What are reject and resolve?
They are functions in Promise class and they call either then or catch and they will have the values that you put in reject and resolve
43
What is set timeout function
Is a js function that delays the excution of function settimeout(function,delay in ms)
44
how to name functions in js?
by using camelCase
45
how to name classes is js?
by using Capital Letter at the start of your class name
46
when using getElementsByClassName how do they appear in the consol?
as a htmlcollection
47
is it a must to use ; in js?
no
48
when using querySelectorAll how do they appear in the consol?
you get nodelist
49
what does nodelist and htmlcollection have?
they have the elements and all the needed info about the,
50
how to make a null value or undefined value in objs?
x:nuill, y:undefined and you can access them by obj.x or obj.y
51
what happens when you console.log(myObjs)
it will print the object normally
52
assume myFunction is a Function name, what is the difference between myFunction ; and myFunction ();
myFunction will not be called unless something ( an event happenns) myFunction () will be called once the page is loaded
53
what happens when you console.log(funtionName) and console.log(funtionName())
.funtionName will print the text of the function .funtionName() will call the function and will print what it returns
54
how to do imports?
import {name} from './index.mjs' or what ever your file name is
55
What is a promise example implementation?
const myFunction =()=>{ return new Promise ((resolve,reject)=>{ setTimeout(() => { const error=true; if(error) resolve("all good") else reject("bad service") }, 3000); }) } myFunction() .then((data)=>{console.log(data)}) .catch((error)=>{console.error(error)})