Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
37 views

Java Scripts Notes: 1. Use - Operator To Default Values

The document provides notes on various JavaScript concepts: 1. It discusses shortcuts for moving and duplicating code lines, using template literals for multi-line strings, the rest operator for functions, getter and setter functions, and validating function arguments. 2. Additional concepts covered include hoisting, let and var, the this keyword, array methods, arrow functions, arguments, factory functions, and adding object properties.

Uploaded by

vineet86
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Java Scripts Notes: 1. Use - Operator To Default Values

The document provides notes on various JavaScript concepts: 1. It discusses shortcuts for moving and duplicating code lines, using template literals for multi-line strings, the rest operator for functions, getter and setter functions, and validating function arguments. 2. Additional concepts covered include hoisting, let and var, the this keyword, array methods, arrow functions, arguments, factory functions, and adding object properties.

Uploaded by

vineet86
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Java Scripts Notes

Alt + up/down  shortcut to move code line

Shift+ alt+ down  duplicate row

1. Use || operator to default values

Var color=’red’;

Let selectedColor = color ||’red’;

2. Template literal
Use template literal (tick operator) to define string across new line
` my name
Is
${person.name}.

`
3. Rest Operator

The rest operator is used to pass varying number of parameters to function.


4. Use Getter and setter function
Instead of creating function to read and write object property, define getter/setter to read it like
object property.

5. Function passed values validation


Use typeof to validate arguments value

Set fulName(value)
{
If(typeof value !== ‘string’)
throw new Error(‘not valid input’)

--Function logic goes here--


}
6. Hoisting
The hoisting is the process of moving function declaration to top of file and this is done
automatically by the JS engine before executing code

7. Let vs var
Var => function – scoped variable
(ES6 specification )Let, const => block scoped variable
8. This
This represent the object that is executing the current function
Function is part of object (Method) object
Function --? Global (windows, global)
When you call function using New keyword, JS creates empty object and use this to point this
new object

9. Array function

Search primitive data type: - indexOf, lastIndexOf, includes

remove elements of array :-pop, shift, splice

Search object type:- find, findIndex

Empty array:- set .length=0, splice(0,number.length)

Combine array: concat, spread operator( […first,’a’ ,…second])


Iterate array: forEach(function(){} )

10. Arrow function

courses.find( function(courses){
return courses.name === 'c';
})

let aa = courses.find( courses =>{


return courses.name === 'c';
})

courses.find( courses => courses.name === 'c')

11. Arguments
12. Factory/constructor Function (Pattern to create object)

Three things happen when new operator is being used.

1. Created empty JS object const x ={}


2. Set this to point this object
3. Return new object

Use Pascal naming to name construction function


13. IIFE

14.
15. Add object property

16.
Define property

You might also like