JavaScript Flashcards
What is JavaScript? What do we use it for?
JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive.
Can we run JavaScript in a web browser, on a server, or both?
JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called the JavaScript engine
What programming paradigm(s) does JS support?
It is a prototype-based, multi-paradigm scripting language that is dynamic, and supports object-oriented, imperative, and functional programming styles.
What are the data types in JS?
Primitive Types:
Boolean - true/false
Null - nonexistent or invalid object address
Undefined - a variable that has not been assigned a value
Number - integers between -2^53 - 1 and 2^53 -1 Includes NaN - Not a Number
BigInt - whole numbers larger than 2^53 -1
String - text data
Symbol - a unique and immutable value.
Non-Primitive:
Objects - a value in memory which is referenced by an identifier
What is the type of NaN? What is the is NaN function?
Not a Number is a number. The isNaN() method returns true if a value is NaN. The isNaN() method converts the value to a number before testing it.
What is the data type of a function?
In JavaScript, functions are objects. But because of an error in JS, functions return a function
What is the data type of an array?
Arrays are just regular objects
What is the difference between undefined and null?
null is an assigned value. It means nothing. undefined means a variable has been declared but not defined yet
What are JS objects? what is the syntax?
In JavaScript, an object is a standalone entity, with properties and type. const student = { firstName: 'ram', class: 10 };
What is JSON? Is it different from JS objects?
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.
What are some ways you can use functions in JS?
Function Declaration - declares a function and runs it
Function Expression - puts a function inside an expression
Generator Function - A function that can stop midway and continue from there
What are the different scopes of variables in JS?
JavaScript variables have only two scopes. Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code. Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function
What are the different ways to declare global variables?
You can define a global variable with var, let, or const and they are defined as global as long as they are declared outside of any function
Is it a best practice to use global variables? Why or why not?
It is not good practice to use global variables.
Global variables can be altered by any part of the code, making it difficult to remember or reason about every possible use.
What are callback functions? What about self-invoking functions?
A callback function is placed in the parameters of a function and can be used to run another function as soon as the original function is complete
A self-invoking expression is invoked (started) automatically, without being called. Add parenthesis around the function followed by parenthesis
What is the difference between == and ===? Which one allows for type coercion?
== - Used for comparing two variables but ignores the datatype
=== - Is used for comparing two variables and also checks that their datatypes are equal as well
What is a Promise?
A promise in JS is an asynchronous function that allows you to define the handlers for success and for failure of a function.
What are arrays in JS? Can you change their size?
Array is a single variable that is used to store different elements. It is often used when we want to store a list of elements and access them by a single variable.JavaScript allows you to change the value of the array length property.