Free Downloadable PDF guide Volume #2 Learn to code JavaScript #javascript
A closure in JavaScript is a function that has access to variables in its parent scope, even after the parent function has returned. Closures are created when a function is defined inside another function, and the inner function retains access to the variables in the outer function’s scope.
Here is an example of a closure in JavaScript:In this example, the innerFunction is a closure because it has access to the variable x and innerVar from the outerFunction even after outerFunction has returned.
A closure has three scope chains:
It has access to its own scope (variables defined between its curly braces {}).
It has access to the outer function’s variables.
It has access to the global variables.
Closures are commonly used in JavaScript for a variety of tasks, such as:
Implementing private methods and variables.
Creating callback functions that retain access to variables from their parent scope.
Creating and returning an object that has access to variables from its parent scope.
JavaScript closures are an important concept and it is important to understand how closures work in JavaScript. It is also important to be aware of the scope chain, and how closures interact with the scope chain.JavaScript Object Notation (JSON) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition – December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
Sample JavaScript Code Laurence Svekis
JavaScript Closure
A closure in JavaScript is a function that has access to the variables in its parent scope, even after the parent function has completed execution. This allows for data to be “closed over” or remembered by the inner function, even after the outer function has returned.
Here, the makeCounter function returns an inner function that has access to the count variable declared in its parent scope, and can “remember” the current count value even after the makeCounter function has completed execution. Each time the inner function is called, it returns the current value of count and increments it by 1.
JavaScript Closure Advanced
In this example, the makeAdder function takes in a single argument x and returns an inner function that takes in a second argument y. The inner function has access to the x variable declared in the parent scope and uses it to add x and y together and return the result.
We can see here that the outer function makeAdder has been executed twice and it returns two different inner functions which are assigned to different variables add5 and add10 and these inner functions are able to remember their respective parent scope values of x.
Node.js allows you to run JavaScript code outside of a browser window, offering powerful tools to interact with a computer filesystem, run web servers, and create terminal applications. Node handles these tasks by running asynchronously, which means that reading user input from a terminal isn’t as simple as calling a getInput() function. In this article, we’ll show you an easy way around that (and some tips and tricks for handling user input) by using a helpful Node module.
readline-sync: This is the third party module that is used for taking the input from the user synchronously. So, the execution of the programs is line by line.
Installing module:
npm install readline-sync
Node handles these tasks by running asynchronously, which means that reading user input from a terminal isn't as simple as calling a getInput() function.
Sample JavaScript Code Laurence Svekis
JavaScript Closure
A closure in JavaScript is a function that has access to the variables in its parent scope, even after the parent function has completed execution. This allows for data to be “closed over” or remembered by the inner function, even after the outer function has returned.
Here, the makeCounter function returns an inner function that has access to the count variable declared in its parent scope, and can “remember” the current count value even after the makeCounter function has completed execution. Each time the inner function is called, it returns the current value of count and increments it by 1.
JavaScript Closure Advanced
In this example, the makeAdder function takes in a single argument x and returns an inner function that takes in a second argument y. The inner function has access to the x variable declared in the parent scope and uses it to add x and y together and return the result.
We can see here that the outer function makeAdder has been executed twice and it returns two different inner functions which are assigned to different variables add5 and add10 and these inner functions are able to remember their respective parent scope values of x.
Node.js allows you to run JavaScript code outside of a browser window, offering powerful tools to interact with a computer filesystem, run web servers, and create terminal applications. Node handles these tasks by running asynchronously, which means that reading user input from a terminal isn’t as simple as calling a getInput() function. In this article, we’ll show you an easy way around that (and some tips and tricks for handling user input) by using a helpful Node module.
readline-sync: This is the third party module that is used for taking the input from the user synchronously. So, the execution of the programs is line by line.
Installing module:
npm install readline-sync
Node handles these tasks by running asynchronously, which means that reading user input from a terminal isn't as simple as calling a getInput() function.
Introduction
Web Storage
WebSQL
IndexedDB
File System Access
Final Considerations
This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2015.
http://www.ivanomalavolta.com
This presentation deals with every possible topics under JSON (JavaScript Object Notation) which every web developers should know.
It is presented by Rajasekhar who works at United Online as a Web Developer
This was a presentation I wrote for a previous employer, aimed at Java developers. The goal was to help them understand some of the new UI conventions I was putting into their application, so that they would be able to develop "smarter" JSP code.
While known for its first-class JSON handling for Java, Jackson is not limited to JSON: with no fewer than 9 supported data formats it can be used for reading and writing data in almost any data format. This talk offers introduction to reading and writing XML and CSV using Jackson.
Understand about what JSON is
Understand the difference between JSON and XML
Understand the context of using JSON with AJAX
Know how to read and write JSON data using PHP
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
We rarely dive into current programming languages, touting the next new framework or the new features that will be out next year. This is about JavaScript the language as it exists today, what I picked up in going from C# to JS, and what C# picked up from JS along the way as well. It is based on Douglas Crockford's seminal book "JavaScript: The Good Parts".
Profile Picture
Use a professional profile picture: A professional headshot is essential for making a good first impression on potential connections and employers.
Headline
Write a compelling headline: Your headline is the first thing people see when they come across your profile, so make sure it accurately reflects your professional brand and grabs their attention.
Your Summary
Optimize your summary: Your summary is your chance to tell your professional story and highlight your unique skills and experiences.
Job Experience
List your current and past job experiences: Make sure to include your current job title, company, and a brief description of your role, as well as your past job experiences.
Highlight Skills
Highlight your skills: Use the skills section to highlight your strengths and areas of expertise. This will make it easier for potential employers to find you when searching for candidates with specific skills.
Get endorsements
Get endorsements and recommendations: Endorsements from your connections and recommendations from past employers can help boost your credibility and make you stand out.
Groups
Join relevant groups: Joining groups in your industry can help you stay up-to-date on industry news and connect with other professionals in your field.
Content
Share valuable content: Share relevant articles, blog posts, and other content to demonstrate your industry knowledge and establish yourself as a thought leader.
Be Active
Be active: Regularly update your profile and engage with your connections by liking, commenting, and sharing their content.
Contact Info
Make it easy to contact you: Include your contact information, such as your email address and phone number, so that potential employers and connections can easily get in touch with you.
Conclusion
Overall, your LinkedIn profile is your professional online identity, so invest time and effort to make it as complete and professional as possible. It’s a living document that should be updated regularly with your latest experiences, skills, and achievements.
Introduction
Web Storage
WebSQL
IndexedDB
File System Access
Final Considerations
This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2015.
http://www.ivanomalavolta.com
This presentation deals with every possible topics under JSON (JavaScript Object Notation) which every web developers should know.
It is presented by Rajasekhar who works at United Online as a Web Developer
This was a presentation I wrote for a previous employer, aimed at Java developers. The goal was to help them understand some of the new UI conventions I was putting into their application, so that they would be able to develop "smarter" JSP code.
While known for its first-class JSON handling for Java, Jackson is not limited to JSON: with no fewer than 9 supported data formats it can be used for reading and writing data in almost any data format. This talk offers introduction to reading and writing XML and CSV using Jackson.
Understand about what JSON is
Understand the difference between JSON and XML
Understand the context of using JSON with AJAX
Know how to read and write JSON data using PHP
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
We rarely dive into current programming languages, touting the next new framework or the new features that will be out next year. This is about JavaScript the language as it exists today, what I picked up in going from C# to JS, and what C# picked up from JS along the way as well. It is based on Douglas Crockford's seminal book "JavaScript: The Good Parts".
Profile Picture
Use a professional profile picture: A professional headshot is essential for making a good first impression on potential connections and employers.
Headline
Write a compelling headline: Your headline is the first thing people see when they come across your profile, so make sure it accurately reflects your professional brand and grabs their attention.
Your Summary
Optimize your summary: Your summary is your chance to tell your professional story and highlight your unique skills and experiences.
Job Experience
List your current and past job experiences: Make sure to include your current job title, company, and a brief description of your role, as well as your past job experiences.
Highlight Skills
Highlight your skills: Use the skills section to highlight your strengths and areas of expertise. This will make it easier for potential employers to find you when searching for candidates with specific skills.
Get endorsements
Get endorsements and recommendations: Endorsements from your connections and recommendations from past employers can help boost your credibility and make you stand out.
Groups
Join relevant groups: Joining groups in your industry can help you stay up-to-date on industry news and connect with other professionals in your field.
Content
Share valuable content: Share relevant articles, blog posts, and other content to demonstrate your industry knowledge and establish yourself as a thought leader.
Be Active
Be active: Regularly update your profile and engage with your connections by liking, commenting, and sharing their content.
Contact Info
Make it easy to contact you: Include your contact information, such as your email address and phone number, so that potential employers and connections can easily get in touch with you.
Conclusion
Overall, your LinkedIn profile is your professional online identity, so invest time and effort to make it as complete and professional as possible. It’s a living document that should be updated regularly with your latest experiences, skills, and achievements.
Top questions with answers and code examples for JavaScript
JavaScript interview questions with answers:
What is closure in JavaScript and how does it work?
Answer: Closure is a feature in JavaScript where a function has access to its outer scope even after the outer function has returned. It is created when a function is defined inside another function, and the inner function retains access to the variables in the outer function’s scope. How do you declare a variable in JavaScript?
Answer: Variables in JavaScript can be declared using the “var”, “let” or “const” keywords. The “var” keyword is used to declare a variable with function scope, while “let” and “const” are used to declare variables with block scope.
Source Code for JavaScript Projects
Learn JavaScript FREE Course - JavaScript How to create Dynamic and Interactive Web pages
https://www.udemy.com/course/javascript-intro-to-learning-javascript/?referralCode=C6245AEDA2A4A0FA8B5A
Top Star Rating over 40000 Students - Source Code Included
Getting started with JavaScript Intro course for Beginners to explore how to apply JavaScript code to update web pages
Get started with JavaScript coding in under 2 hours. Fast paced course to get you coding quickly. Dive right in start coding right away. Learn the core and fundamentals needed to create interactive and dynamic web page content. Let your web pages come to life! Quick start with everything you need to code JavaScript. Source code included - try it for yourself and see what you can do with JavaScript.
Build over 20 mini JavaScript Projects with full source code
https://skl.sh/3yJdYM0
Web Developer Setup use of Editor for JavaScript Code
JavaScript Projects DOM Interactive Dynamic web pages Introduction web development Course Resource Guide.
Getting started with JavaScript DOM coding and development
Web Developer Setup use of Editor for JavaScript Code
JavaScript Resources to explore more about JavaScript
JavaScript DOM Object Selecting Page elements and more
JavaScript querySelectorAll Get Page Elements Select ALL
Page Events Element Event Listener access page content with JavaScript
JavaScript and Page Input Values from Page Elements
How to use JavaScript Request Animation Frame
JavaScript Starter Projects DOM Simple Projects to Start Coding
How to make Interactive DOM list saving to localstorage
JavaScript Component Create a Star Rating Project
JavaScript Game within the DOM Coin Toss Game Project
JavaScript Typing Challenge Game with JavaScript DOM
JavaScript DOM fun with Page Elements Moving Storing Keypress
JavaScript Combo Guessing Game Exercise
JavaScript Shape Clicker Game Click the shape quickly to win
JavaScript Number Guessing Game with Game Logic
JavaScript DOM Interactive Components and Useful Projects
Pure JavaScript Accordion hide and show page elements
JavaScript Drag and Drop Simple Boxes Component
Dynamic Drag and Drop
JavaScript Email Extractor Mini Project
Create a Quiz with Javascript JSON quiz tracker
JavaScript Image Preview File Reader Example
JavaScript Interactive Dice Game with Page elements
JavaScript Dice Game Challenge Lesson
JavaScript DOM Fun Projects Interactive DOM Elements
JavaScript Tip Calculator Project
Tip Calculator Project Part 1
Tip Calculator Project Part 2
Pure JavaScript Calculator DOM page elements Project
JavaScript Calculator Part 1
JavaScript Calculator Part 2
JavaScript Calculator Part 3
JavaScript Bubble Popping DOM Game Coding project
How to move a Page Element With JavaScript DOM Mover Example
Collision Detection between Page elements with JavaScript DOM
JavaScript DOM Interactive Game
Chrome DevTools Introduction 2020 Web Developers GuideLaurence Svekis ✔
Learn how use Chrome DevTools improve on Debugging, Customize look and feel and learn some shortcuts for Web development
Course covers
Open DevTools
Element Panel
Where to compute and get box model details
using the Console and JavaScript coding
Snippets of code running and saved in the console
Access local filesystem with DevTOols
Network for file load times and debugging
Application tab for session and local storage values
Audit Panel and how to get website improvement report
Shortcuts and getting more help with DevTools
Taught by an instructor with over 20 years of web development experience ready to help you learn about DevTools
Over 200 Pages of resources and code snippets to learn JavaScript and JavaScript DOM manipulation. JavaScript is the most popular web programming language and this eBook will help you learn more about JavaScript Coding
Get this Course
https://www.udemy.com/javascript-course-dom/?couponCode=SLIDESHARE
Document Object Model Power your websites make things happen online - JavaScript to create interactive web pages
Source code making it easy for you to try the code and experiment learning the code.
Challenges and tips to get you coding quickly.
Make you web pages come to life
DOM what it is
Element selection
Multiple element selection
Element manipulation - update content and select attributes
Elements and classes add remove and toggle
Traversing children and parents
Element style attribute
Challenge #1 image popup window
Create elements
Click events
Challenge #2 click event create elements
Challenge #3 click change background
Event Object
Key press event
Mouse move events
Challenge #4 - List items advanced remove,create element, click
Event bubbling and capturing
No libraries, no shortcuts just learning JavaScript making it DYNAMIC and INTERACTIVE web application.
JavaScript Advanced - Useful methods to power up your codeLaurence Svekis ✔
Get this Course
https://www.udemy.com/javascript-course-plus/?couponCode=SLIDESHARE
Useful methods and JavaScript code snippets power up your code and make even more happen with it.
This course is perfect for anyone who has fundamental JavaScript experience and wants to move to the next level. Use and apply more advanced code, and do more with JavaScript.
Everything you need to learn more about JavaScript
Source code is included
60+ page Downloadable PDF guide with resources and code snippets
3 Challenges to get you coding try the code
demonstrating useful JavaScript methods that can power up your code and make even more happen with it.
Course lessons will cover
JavaScript Number Methods
JavaScript String Methods
JavaScript Math - including math random
DOMContentLoaded - DOM ready when the document has loaded.
JavaScript Date - Date methods and how to get set and use date.
JavaScript parse and stringify - strings to objects back to strings
JavaScript LocalStorage - store variables in the user browser
JavaScript getBoundingClientRect() - get the dimensions of an element
JavaScript Timers setTimeout() setInterval() requestAnimationFrame() - Run code when you want too
encodeURIComponent - encoding made easy
Regex - so powerful use it to get values from your string
prototype - extend JavaScript objects with customized powers
Try and catch - perfect for error and testing
Fetch xHR requests - bring content in from servers
and more
No libraries, no shortcuts just learning JavaScript making it DYNAMIC and INTERACTIVE web application.
Step by step learning with all steps included.
Monster JavaScript Course - 50+ projects and applicationsLaurence Svekis ✔
Get this Course
https://www.udemy.com/javascript-course-projects/?couponCode=SLIDESHARE
Portfolio builder loaded with projects and applications that you can use, extend on and enhance to add to your portfolio
JUST GOT BIGGER - more updates to come - YOU FOUND IT
Grow your portfolio - showcase what you can build with JavaScript
Learn JavaScript have fun with interactive and dynamic web applications.
Over 529 downloadable resources - 57 articles - 43+ hours on-demand video, 57 Sections
Over 614 HD video lessons
Over 51+ projects and web applications. Projects can be used as started projects to extend and enhance. All JavaScript focused.
4 downloadable ebook guides 200 pages and 3 x 60 pages - with code and resource links
No libraries JUST JAVASCRIPT and JAVASCRIPT DOM
This is the course you've been looking for..........
Everything you need to get started with JavaScript, expand your knowledge about using JavaScript, and more included.
It’s arrived, and bigger than expected!!!
For anyone who wants to supercharge their JavaScript learning - building and applying JavaScript to over 50 projects and challenges… this course is for YOU!!!!
From JavaScript beginners to all levels, course is presented in a fun interactive format that will challenge you. Move through the lessons of the course as you want to learn them, variety of ways to benefit from it. Learn alongside, try before you see the solution, try after you view the solution. It’s up to you! Unique format for learning encouraging you to try the code. Of course source code is included in every step of the way.
Most often asked for ARE PROJECTS - and this course delivers! Over 50 and will grow over time as more projects and challenges get added. You can select the projects you want to do or take them in order, it’s up to you.
Loaded with games and so many mini projects guaranteed to help you learn more about JavaScript and DOM manipulation. All JavaScript code no libraries or short cuts.
Explore how to apply JavaScript to create interactive and dynamic web content - that will impress your friends.
Extend on the projects and add them to your portfolio, to showcase skills you have learned.
Useful real world projects coded with simple JavaScript for developers of all levels.
No better way to learn than to try the code and produce something fun and useful with it. Learn to create amazing things with JavaScript bringing your web content to life.
This will keep you busy and provide you the opportunity to learn and experiment with code. Try it. All the projects are designed in a starter type format so that you can build on them and customize to make it your own.
Portfolio Builder 50+ projects
This course includes full introduction to coding with JavaScript, all core syntax and how to apply it to make things happen. Create your own code - loaded with challenges and code snippets.
JavaScript Objects and OOP Programming with JavaScriptLaurence Svekis ✔
Get this Course
https://www.udemy.com/javascript-objects-oop/?couponCode=SLIDESHARE
Use objects to create amazing things with JavaScript power up your applications OOP JavaScript coding
Learn the core fundamentals of JavaScript and how to use JavaScript creating web applications.
GET the Course - https://www.udemy.com/javascript-code-course/?couponCode=SLIDESHARE
Learn JavaScript Language Fundamentals and start coding JavaScript Today.
Source Code is included so you can try the code.
Resources and tips are provided throughout the course when appropriate.
Modern JavaScript focused means that we do cover current syntax as well as foundational code. No frameworks or JavaScript libraries you can do it all with regular vanilla JavaScript.
All you need is a browser to see JavaScript in action and with a few lines of code you can do a whole lot. It’s easy let us show you.
Course covers
Setup you working development environment and get ready to write some code.
What JavaScript is and how code works. Tools and resources used to write JavaScript
How to create JavaScript Code and run it in your browser
Comments and debugging with the console
Variables and how to create and store values in code
Declaring variables assigning values
Using let and const as variables
Strings Numbers and Boolean data types
Other data types null, undefined
Best practices and rules to name variables
Using JavaScript windows methods alert and prompt
Creating template literals
Challenge #1 Using Template literals in code
JavaScript type conversion and how it works
JavaScript Operators
Comparison and Assignment operators
Challenge #2 to create a Miles to Kilometers Converter
Truthy or Falsy
JavaScript Conditions if else statements
JavaScript Conditions else if statements
Using Short ternary operator
Conditions with Multiple conditions and logical operators
Challenge #3 - Hello Greeter
JavaScript Switch statement
JavaScript Functions
JavaScript Functions arguments and default values
JavaScript Functions return values
JavaScript click events on elements
Function declaration vs expression
Function scope global vs local
Function recursion
IIFE (Immediately Invoked Function Expression)
ES6 Arrow format
JavaScript Objects
Object Method and const
Functions to create Objects
JavaScript Arrays
Array methods to do more with arrays
Array filter
JavaScript Loops and iteration
forEach, object and array data
Challenge #4 - Loops Array builder
JavaScript Map
No libraries, no shortcuts just learning JavaScript making it DYNAMIC and INTERACTIVE web application.
Step by step learning with all steps included.
Beginner JavaScript knowledge is required as the course covers only JavaScript relevant to the building of the game. Also HTML and CSS knowledge is essential as scope of this course is all JavaScript focused.
Along with friendly support in the Q&A to help you learn and answer any questions you may have.
Explore how you can easily add advanced functionality to your web projects by adding jQuery. JQuery for web development
https://www.udemy.com/web-development-introduction-to-jquery/?couponCode=SLIDESHARE
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
1. JavaScript Closure Explained
https://youtu.be/7vyHA0aODeU
A closure in JavaScript is a function that has access to variables in
its parent scope, even after the parent function has returned.
Closures are created when a function is defined inside another
function, and the inner function retains access to the variables in
the outer function's scope.
Here is an example of a closure in JavaScript:
code example
function outerFunction(x) {
var innerVar = 4;
function innerFunction() {
return x + innerVar;
}
return innerFunction;
Laurence Svekis https://basescripts.com/
2. }
var closure = outerFunction(2);
console.log(closure()); // Output: 6
In this example, the innerFunction is a closure because it has
access to the variable x and innerVar from the outerFunction even
after outerFunction has returned.
A closure has three scope chains:
1. It has access to its own scope (variables defined between its
curly braces {}).
2. It has access to the outer function's variables.
3. It has access to the global variables.
Closures are commonly used in JavaScript for a variety of tasks,
such as:
● Implementing private methods and variables.
● Creating callback functions that retain access to variables
from their parent scope.
● Creating and returning an object that has access to variables
from its parent scope.
JavaScript closures are an important concept and it is important
to understand how closures work in JavaScript. It is also
important to be aware of the scope chain, and how closures
interact with the scope chain.
<!DOCTYPE html>
<html>
<head>
<title>Learn JavaScript</title>
Laurence Svekis https://basescripts.com/
4. JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON) is a lightweight
data-interchange format that is easy for humans to read and
write and easy for machines to parse and generate. It is based on
a subset of the JavaScript Programming Language, Standard
ECMA-262 3rd Edition - December 1999. JSON is a text format
that is completely language independent but uses conventions
that are familiar to programmers of the C-family of languages,
including C, C++, C#, Java, JavaScript, Perl, Python, and many
others. These properties make JSON an ideal data-interchange
language.
https://youtu.be/wdoIV_09xAc
Laurence Svekis https://basescripts.com/
5. Here is an example of JSON data:
{
"name": "Laurence Svekis",
"age": 41,
"address": {
"street": "10 Main St",
"city": "New York",
"state": "NY",
"zip": 10001
},
"phoneNumbers": [
{
"type": "home",
"number": "212 123-1234"
},
{
"type": "work",
"number": "646 123-4567"
}
]
}
JavaScript provides methods JSON.stringify() and JSON.parse()
to convert between JSON and JavaScript objects.
Example of converting JavaScript object to JSON:
Code Example :
const object = { name: 'John Doe', age: 35 };
Laurence Svekis https://basescripts.com/
6. const json = JSON.stringify(object);
console.log(json);
Example of converting JSON to JavaScript object:
Code Example :
const json = '{"name":"John Doe","age":35}';
const object = JSON.parse(json);
console.log(object.name); // "John Doe"
In summary, JSON is a lightweight data interchange format that
is easy for humans to read and write, and easy for machines to
parse and generate. It is based on a subset of JavaScript and can
be used with many programming languages. JavaScript provides
built-in methods for converting between JSON and JavaScript
objects.
There are several ways to get JSON data with JavaScript. One
common method is to use the fetch() function to make an HTTP
request to a server that returns JSON data. The fetch() function
returns a promise that resolves to a response object, from which
the JSON data can be extracted using the json() method.
Here is an example of how to get JSON data from a remote
server:
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
Laurence Svekis https://basescripts.com/
7. });
Another way to get JSON data is to load it from a local file using
the XMLHttpRequest object or the fetch() function.
Here is an example of how to get JSON data from a local file:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'data.json', true);
xhr.responseType = 'json';
xhr.onload = function() {
if (xhr.status === 200) {
console.log(xhr.response);
}
};
xhr.send();
In summary, there are several ways to get JSON data with
JavaScript, including using the fetch() function to make an HTTP
request to a server that returns JSON data or by loading JSON
data from a local file using the XMLHttpRequest object or the
fetch() function. Once you have the data you can use json() to
access the data.
Laurence Svekis https://basescripts.com/
11. }
JavaScript Create Element List
The document.createElement() method in JavaScript is used to
create a new HTML element with a specified tag name. The
method takes a single argument, which is the tag name of the
element to be created. For example,
document.createElement("div") creates a new div element. The
newly created element can be accessed and modified through the
DOM API, such as adding content, attributes, and styles to the
element. It can also be added to the document by using methods
such as appendChild() or insertAdjacentHTML().
In the below example we will be creating a dynamic list, all the
elements are created using JavaScript, adding the button for
interaction when the user wants to add new people to the list.
const myArr = ['Laurence','Susan','Lisa'];
const output = document.querySelector('.output');
Laurence Svekis https://basescripts.com/
13. myArr.forEach(ele => {
adder(ele);
})
}
Create an interactive table list of item object
values from a JavaScript array.
Create a list of items within a table using JavaScript. Data is
contained within an array with object values.
<!DOCTYPE html>
<html>
<head>
<title>Learn JavaScript</title>
<style>
table{
width:100%;
}
td:first-child{
width:10%;
Laurence Svekis https://basescripts.com/
16. }
How to Create Page Elements with JavaScript
How to Create Page Elements and make them Interactive with
Event LIsteners
There are several ways to create page elements with JavaScript,
including:
Using the document.createElement() method, which creates a
new element with the specified tag name. For example, the
following code creates a new div element:
let newDiv = document.createElement("div");
Using the innerHTML property to add HTML content to an existing
element. For example, the following code adds a new p element
to an existing div element with an id of "container":
let container = document.getElementById("container");
container.innerHTML += "<p>Hello World</p>";
Using the appendChild() method to add a new element as a child
of an existing element. For example, the following code adds a
new p element as a child of an existing div element with an id of
"container":
let container = document.getElementById("container");
let newP = document.createElement("p");
Laurence Svekis https://basescripts.com/
17. newP.innerHTML = "Hello World";
container.appendChild(newP);
Using the insertAdjacentHTML() method to insert HTML content at
a specific position relative to an existing element. For example,
the following code adds a new p element before an existing div
element with an id of "container":
let container = document.getElementById("container");
container.insertAdjacentHTML("beforebegin", "<p>Hello
World</p>");
You can also use any of the above methods to add CSS styles,
classes and attributes to the newly created elements.
Coding Example of how to insert page content
, html elements into your DOM page.
Laurence Svekis https://basescripts.com/