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.
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
hashing is encryption process mostly used in programming language for security purpose.
This presentation will you understand all about hashing and also different techniques used in it for encryption process
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
hashing is encryption process mostly used in programming language for security purpose.
This presentation will you understand all about hashing and also different techniques used in it for encryption process
Directed Acyclic Graph Representation of basic blocks is the most important topic of compiler design.This will help for student studying in master degree in computer science.
What is Constructors and Destructors in C++ (Explained with Example along wi...Pallavi Seth
This slide will help you to understand the concept of constructors and destuctors in C++. This slide is made by keeping not only the final exam point of view but Mcq type questions which are quite often seen in competitive exams.
Slides from my talk at Reversim 2021 convention (also passed a talk with the same slide at PyWeb-IL, 2022-03) in Tel-Aviv, Israel.
The recording of the talk is on youtube, here: https://www.youtube.com/watch?v=ahGLUdW3cqk&ab_channel=Reversim.
You can find more information, and services to help you get started on my website, https://propertybasedtesting.com.
The talk introduces property-based testing, a software testing technique that improves the ROI of automated tests.
While with standard tests, we need to work hard, hand-coding many examples - with property-based tests the computer generates hundreds or thousands of tests for us.
The random generation saves us a lot of effort, and also has a surprising tendency to come up with edge cases we would have never thought to test.
This helps us find bugs sooner and more easily, and have more confidence in our code.
The talk covered the basics of property-based tests.
It also gave the feeling for the power and variety of real-world use cases, by taking a CRUD web application and letting our test explore the application’s external API and find bugs in edge cases we didn’t know.
See the last slides for extra resources.
LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. It is a commonly used language for artificial intelligence (AI) programming.
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
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.
Directed Acyclic Graph Representation of basic blocks is the most important topic of compiler design.This will help for student studying in master degree in computer science.
What is Constructors and Destructors in C++ (Explained with Example along wi...Pallavi Seth
This slide will help you to understand the concept of constructors and destuctors in C++. This slide is made by keeping not only the final exam point of view but Mcq type questions which are quite often seen in competitive exams.
Slides from my talk at Reversim 2021 convention (also passed a talk with the same slide at PyWeb-IL, 2022-03) in Tel-Aviv, Israel.
The recording of the talk is on youtube, here: https://www.youtube.com/watch?v=ahGLUdW3cqk&ab_channel=Reversim.
You can find more information, and services to help you get started on my website, https://propertybasedtesting.com.
The talk introduces property-based testing, a software testing technique that improves the ROI of automated tests.
While with standard tests, we need to work hard, hand-coding many examples - with property-based tests the computer generates hundreds or thousands of tests for us.
The random generation saves us a lot of effort, and also has a surprising tendency to come up with edge cases we would have never thought to test.
This helps us find bugs sooner and more easily, and have more confidence in our code.
The talk covered the basics of property-based tests.
It also gave the feeling for the power and variety of real-world use cases, by taking a CRUD web application and letting our test explore the application’s external API and find bugs in edge cases we didn’t know.
See the last slides for extra resources.
LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. It is a commonly used language for artificial intelligence (AI) programming.
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
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.
JavaScript Multithread or Single Thread.pptxRAHITNATH
The most functional yet intricately constructed programming language is JavaScript. Understanding how the syntax is used in engines, such as V8 engines for chromium, is challenging. We are successfully completing tasks in Chrome at the same time. This PPT will assist you in learning about the most crucial aspects and use of JavaScript, which will help you comprehend when and where the language is required. Java provides a superior platform by using multi-threading ways to optimize the process, but how can JavaScript manage to achieve the same thing even in a better way to compile and provide us a real-time user interface on webpages even after a significant amount of time has passed.
JavaScript's non-blocking approaches offer a better method of process resolution and execution with regard to load and priority to improve user experience. Even better are the non-blocking approaches and some browser architecture. The topic focuses on JavaScript's end-to-end workflow in Chrome's V8 engine and how it distributes its load and processes with the aid of queues made available by Chrome's architectural design.
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".
Workshop slides from the Alt.Net Seattle 2011 workshop. Presented by Wes Dyer and Ryan Riley. Get the slides and the workshop code at http://rxworkshop.codeplex.com/
JavaScript basics
JavaScript event loop
Ajax and promises
DOM interaction
JavaScript object orientation
Web Workers
Useful Microframeworks
This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2014.
http://www.ivanomalavolta.com
JavaScript Fundamentals with Angular and LodashBret Little
The purpose of this presentation is also largely to explain some of the fun parts of JavaScript (dynamic function invocation with reflection, dynamic arguments, etc). I don't necessarily encourage putting complex logic throughout your templates with lodash, though there may be times it is appropriate.
Lets talk about lodash and how it can easily be married to Angular. Using a six line filter, I will expose the power of lodash directly within angular templates. This will be an introduction to lodash, angular templates, and we'll talk about scope and reflection within JavaScript.
JavaScript basics
JavaScript event loop
Ajax and promises
DOM interaction
JavaScript object orientation
Web Workers
Useful Microframeworks
This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2016.
http://www.ivanomalavolta.com
This is presentation from Nemetschek Bulgaria - one of the partners of HackBulgaria's JavaScript course.
The topic is Async JS -How does the event loop in JS works and what are the benefits of the Promises.
Promises are a popular pattern for asynchronous operations in JavaScript, existing in some form in every client-side framework in widespread use today. We'll give a conceptual and practical intro to promises in general, before moving on to talking about how they fit into Angular. If you've ever wondered what exactly $q was about, this is the place to learn!
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.
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.
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.
A Strategic Approach: GenAI in EducationPeter 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.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
2024.06.01 Introducing a competency framework for languag learning materials ...
JavaScript Interview Questions 2023
1. 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.
Closure Example 1:
function outerFunction(x) {
return function innerFunction(y) {
return x + y;
};
}
const add5 = outerFunction(5);
console.log(add5(3)); // 8
Closure Example 2:
function outerFunction(x) {
return function innerFunction(y) {
return x + y;
};
}
const add5 = outerFunction(5);
console.log(add5(3)); // 8
Closure Example A counter function:
function createCounter() {
let count = 0;
return function() {
Laurence Svekis https://basescripts.com/
2. return ++count;
};
}
const counter = createCounter();
console.log(counter()); // 1
console.log(counter()); // 2
Closure Example A function returning another function:
function greeting(message) {
return function(name) {
console.log(`${message} ${name}!`);
};
}
const sayHi = greeting('Hi');
const sayHello = greeting('Hello');
sayHi('John'); // Hi John!
sayHello('Jane'); // Hello Jane!
Closure Example A timer:
function setTimer(duration) {
let timeoutId;
return function() {
clearTimeout(timeoutId);
timeoutId = setTimeout(function() {
console.log(`${duration} seconds have passed.`);
}, duration * 1000);
};
}
const timer1 = setTimer(3);
const timer2 = setTimer(5);
Laurence Svekis https://basescripts.com/
3. timer1();
timer2();
Closure Example A module:
function createModule(name) {
let module = {};
return function(data) {
module[name] = data;
return module;
};
}
const createPerson = createModule('person');
const createAddress = createModule('address');
const person = createPerson({ name: 'John', age: 32 });
const address = createAddress({ street: '123 Main St',
city: 'San Francisco' });
console.log(person); // { person: { name: 'John', age:
32 } }
console.log(address); // { address: { street: '123 Main
St', city: 'San Francisco' } }
Closure Example A function to maintain state:
function createToggler() {
let state = false;
return function() {
state = !state;
return state;
};
}
const toggler = createToggler();
console.log(toggler()); // true
Laurence Svekis https://basescripts.com/
4. console.log(toggler()); // false
Can you explain hoisting in JavaScript?
Answer: Hoisting is a behavior in JavaScript where variable and
function declarations are moved to the top of their scope,
regardless of where they are declared in the code. This means
that variables and functions can be called before they are
declared, but the value of variables will be undefined until they
are assigned a value.
Hoisting Example 1:
console.log(x); // undefined
var x = 5;
What is the difference between == and === in JavaScript?
Answer: The double equals (==) performs type coercion, which
means it converts the data type of one operand to match the data
type of the other operand before making a comparison. The triple
equals (===) does not perform type coercion and only returns
true if both operands have the same data type and value.
== vs === Example 1:
console.log(5 == "5"); // true
console.log(5 === "5"); // false
console.log(null == undefined); // true
console.log(null === undefined); // false
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.
Variable declaration 1:
Laurence Svekis https://basescripts.com/
5. var x = 5;
let y = 10;
const z = 15;
Variable declaration 2:
let x = 5;
x = 10;
console.log(x); // 10
const z = [1, 2, 3];
z.push(4);
console.log(z); // [1, 2, 3, 4]
Can you explain the event loop in JavaScript?
Answer: The event loop in JavaScript is a mechanism that allows
the execution of code to be scheduled in a non-blocking way. The
event loop continuously checks the message queue for new
messages, and if there is a message, it executes the
corresponding callback function. This allows the JavaScript engine
to handle multiple events and execute code in a responsive and
efficient manner.
Event loop 1:
console.log('Start');
setTimeout(function() {
console.log('Timeout');
}, 0);
console.log('End');
Event loop 2:
console.log('Start');
setTimeout(function() {
console.log('Timeout');
Laurence Svekis https://basescripts.com/
6. }, 2000);
console.log('End');
Event loop Using setTimeout with a queue:
console.log('Start');
setTimeout(() => console.log('Timeout 1'), 0);
setTimeout(() => console.log('Timeout 2'), 0);
console.log('End');
This will log:
Start
End
Timeout 1
Timeout 2
Event loop Handling multiple callbacks with setInterval:
let count = 0;
const intervalId = setInterval(() => {
console.log(`Interval: ${count++}`);
if (count === 5) {
clearInterval(intervalId);
}
}, 1000);
This will log:
Interval: 0
Interval: 1
Interval: 2
Interval: 3
Interval: 4
Laurence Svekis https://basescripts.com/
7. Event loop Chaining promises:
const delay = (duration) => new Promise(resolve =>
setTimeout(resolve, duration));
console.log('Start');
delay(1000)
.then(() => console.log('Promise 1'))
.then(() => delay(1000))
.then(() => console.log('Promise 2'));
console.log('End');
This will log:
Start
End
Promise 1
Promise 2
Event loop Processing multiple tasks with setImmediate:
console.log('Start');
setImmediate(() => console.log('Immediate 1'));
setImmediate(() => console.log('Immediate 2'));
console.log('End');
This will log:
Start
End
Immediate 1
Immediate 2
Laurence Svekis https://basescripts.com/
8. What is the difference between null and undefined in
JavaScript?
Answer: Undefined means a variable has been declared but has
not been assigned a value, while null is a value assigned to a
variable that represents no value or no object.
null vs undefined example:
let x;
console.log(x); // undefined
x = null;
console.log(x); // null
What is a JavaScript callback function?
Answer: A callback function is a function passed as an argument
to another function, which is then executed at a later time.
Callback functions are commonly used in JavaScript to handle
asynchronous operations, such as making a network request or
setTimeout().
Callback function example 1:
function sayHello(name, callback) {
console.log(`Hello, ${name}!`);
callback();
}
sayHello('John', function() {
console.log('Callback executed');
});
Callback function example 2:
function calculate(a, b, callback) {
const result = a + b;
callback(result);
Laurence Svekis https://basescripts.com/
9. }
calculate(5, 3, function(result) {
console.log(result); // 8
});
A simple callback with setTimeout:
const log = (message) => console.log(message);
setTimeout(() => log('Timeout'), 1000);
A callback with Array.forEach:
const numbers = [1, 2, 3, 4, 5];
numbers.forEach((number) => console.log(number));
A callback with Array.map:
const numbers = [1, 2, 3, 4, 5];
const doubledNumbers = numbers.map((number) => number *
2);
console.log(doubledNumbers);
A callback with Array.filter:
const numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter((number) => number % 2
=== 0);
console.log(evenNumbers);
A callback with Array.reduce:
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((total, number) => total + number,
0);
console.log(sum);
Laurence Svekis https://basescripts.com/
10. A callback with Array.sort:
const names = ['John', 'Jane', 'Jim', 'Jake'];
const sortedNames = names.sort((a, b) => a.localeCompare(b));
console.log(sortedNames);
A callback with Object.keys:
const person = { name: 'John', age: 30, city: 'London' };
Object.keys(person).forEach((key) => console.log(`${key}:
${person[key]}`));
A callback with Promise.then:
const delay = (duration) => new Promise(resolve =>
setTimeout(resolve, duration));
console.log('Start');
delay(1000)
.then(() => console.log('Promise'));
console.log('End');
A callback with EventTarget.addEventListener:
const button = document.getElementById('button');
button.addEventListener('click', () => console.log('Clicked'));
A callback with XMLHttpRequest.onload:
const request = new XMLHttpRequest();
request.open('GET',
'https://jsonplaceholder.typicode.com/posts');
request.onload = () => {
if (request.status === 200) {
console.log(JSON.parse(request.responseText));
} else {
console.error(request.statusText);
}
Laurence Svekis https://basescripts.com/
11. };
request.send();
How do you declare a function in JavaScript?
Answer: Functions in JavaScript can be declared using the
"function" keyword followed by the function name, its parameters
in parentheses, and its code block in curly braces. Functions can
also be declared using function expressions and arrow functions.
Function declaration 1:
function sayHello(name) {
console.log(`Hello, ${name}!`);
}
const greet = function(name) {
console.log(`Hello, ${name}!`);
};
const hello = name => console.log(`Hello, ${name}!`);
Function declaration 2:
function sayHi(name) {
console.log(`Hi, ${name}!`);
}
const greet = function(name) {
console.log(`Hello, ${name}!`);
};
const hello = name => console.log(`Hello, ${name}!`);
sayHi('John'); // Hi, John!
greet('John'); // Hello, John!
hello('John'); // Hello, John!
Laurence Svekis https://basescripts.com/
12. What is the difference between let and var in JavaScript?
Answer: The "let" and "var" keywords are used to declare
variables in JavaScript, but they have different scoping rules.
Variables declared with "var" have function scope, which means
they can be accessed within the entire function, while "let"
variables have block scope, which means they can only be
accessed within the block they are declared in.
let vs var example 1:
var x = 5;
if (true) {
var x = 10;
}
console.log(x); // 10
let y = 5;
if (true) {
let y = 10;
}
console.log(y); // 5
let vs var example 2:
for (var i = 0; i < 5; i++) {
console.log(i);
}
console.log(i); // 5
for (let j = 0; j < 5; j++) {
console.log(j);
}
console.log(j); // ReferenceError: j is not defined
Can you explain the "this" keyword in JavaScript?
Laurence Svekis https://basescripts.com/
13. Answer: The "this" keyword in JavaScript refers to the object that
the function is a method of. Its value depends on how the
function is called, and it can be set using bind, call or apply
methods. If a function is not a method of an object, "this" refers
to the global object (window in the browser).
"this" keyword example 1:
const person = {
name: 'John',
sayHello: function() {
console.log(`Hello, I'm ${this.name}`);
}
};
person.sayHello(); // Hello, I'm John
const greet = person.sayHello;
greet(); // Hello, I'm undefined
"this" keyword example 2:
const car = {
brand: 'Tesla',
drive: function() {
console.log(`Driving a ${this.brand} car`);
}
};
car.drive(); // Driving a Tesla car
const driveCar = car.drive;
driveCar(); // Driving a undefined car
examples of the this keyword in JavaScript:
this in an object method:
const person = {
name: 'John',
sayHello: function () {
Laurence Svekis https://basescripts.com/
14. console.log(`Hello, my name is ${this.name}`);
}
};
person.sayHello();
this in a class method:
class Person {
constructor(name) {
this.name = name;
}
sayHello() {
console.log(`Hello, my name is ${this.name}`);
}
}
const john = new Person('John');
john.sayHello();
this in an arrow function:
const person = {
name: 'John',
sayHello: () => {
console.log(`Hello, my name is ${this.name}`);
}
};
person.sayHello();
this in a function passed as a callback:
const person = {
name: 'John'
Laurence Svekis https://basescripts.com/
15. };
const logName = function () {
console.log(`Hello, my name is ${this.name}`);
};
setTimeout(logName.bind(person), 1000);
this in an event handler:
const button = document.getElementById('button');
button.addEventListener('click', function () {
console.log(`Button with ID "${this.id}" was clicked`);
});
this in an object constructor:
function Person(name) {
this.name = name;
}
const john = new Person('John');
console.log(john.name);
this in a closure:
const person = {
name: 'John',
sayHello: function () {
const that = this;
setTimeout(function () {
console.log(`Hello, my name is ${that.name}`);
}, 1000);
}
};
person.sayHello();
Laurence Svekis https://basescripts.com/
16. this in a prototype method:
function Person(name) {
this.name = name;
}
Person.prototype.sayHello = function () {
console.log(`Hello, my name is ${this.name}`);
};
const john = new Person('John');
john.sayHello();
this in a dynamic method:
const person = {
name: 'John'
};
const method = 'sayHello';
person[method] = function () {
console.log(`Hello, my name is ${this.name}`);
};
person.sayHello();
this in a nested function:
const person = {
name: 'John',
sayHello: function () {
const nested = function () {
console.log(`Hello, my name is ${this.name}`);
};
nested.call(person);
}
};
person
Laurence Svekis https://basescripts.com/
17. JavaScript interview questions with code
examples:
What is hoisting in JavaScript and how does it work?
console.log(hoistedVariable); // undefined
var hoistedVariable = 'This is a hoisted variable';
console.log(notHoisted); // ReferenceError: notHoisted is not
defined
let notHoisted = 'This is not a hoisted variable';
What is closure in JavaScript and how is it useful?
function outerFunction(x) {
return function innerFunction(y) {
return x + y;
};
}
const add5 = outerFunction(5);
console.log(add5(3)); // 8
What is the difference between == and === in JavaScript?
console.log(1 == '1'); // true
console.log(1 === '1'); // false
What is the difference between null and undefined in
JavaScript?
let variable1;
console.log(variable1); // undefined
let variable2 = null;
console.log(variable2); // null
Laurence Svekis https://basescripts.com/
18. How does asynchronous code work in JavaScript?
console.log('Before setTimeout');
setTimeout(function () {
console.log('Inside setTimeout');
}, 1000);
console.log('After setTimeout');
What is the difference between let and var in JavaScript?
if (true) {
var variable1 = 'This is a var variable';
let variable2 = 'This is a let variable';
}
console.log(variable1); // This is a var variable
console.log(variable2); // ReferenceError: variable2 is not defined
How do you declare a variable in JavaScript?
var variable1 = 'This is a var variable';
let variable2 = 'This is a let variable';
const variable3 = 'This is a const variable';
What is the difference between forEach and map in
JavaScript?
const numbers = [1, 2, 3, 4, 5];
numbers.forEach(function (number) {
console.log(number);
});
const doubledNumbers = numbers.map(function (number) {
return number * 2;
});
console.log(doubledNumbers);
Laurence Svekis https://basescripts.com/
19. What is the difference between function and arrow
function in JavaScript?
function regularFunction(x, y) {
return x + y;
}
const arrowFunction = (x, y) => x + y;
console.log(regularFunction(1, 2)); // 3
console.log(arrowFunction(1, 2)); // 3
How do you declare an object in JavaScript?
const objectLiteral = {
key1: 'value1',
key2: 'value2'
};
const objectConstructor = new Object();
objectConstructor.key1 = 'value1';
objectConstructor.key2 = 'value2';
Laurence Svekis https://basescripts.com/