Datatypes:
Number type, String type, Boolean type
innerText = Take all the text inside an element.
innerHTML = Takes all the text and child element.
Onclick
<button id="increment-btn" onclick="increment()">Increment</button>
Why === instead of == ?
eg 100 == "100" - double equal ignores the fact that one is number and other is string and return the value to True. === strictly checks it, if both the values are of diff data types, then === wont return it to true.
querySelector - with this we can select element by its id or class or by the element name.
ed: document.querySelector("#id")
Array
featuredPost.length - length property will return length of an array.
cards.push(6) - push method pushes a value to the array.
To acces a value in an array = arrayName.keyName
JS Random number:
let randomNumber = Math.floor(Math.random()*13) + 1
Event Listner
inputBtn.addEventListner("click", function(){
console.log(".......")
})
const - cannot be reassigned
if we want to reassign use let, else use const.
creating element
ulEl.innerHTML += "<li>" + myLeads[i] + "</li>"
const li = document.createElement("li")
li.textContent = myLeads[i]
ulEl.append(li)
<a href='" + myLeads[i] + "'>" + myLeads[i] + "</a>
This is how to put a link inside a in innerhtml purpose.
Template strings-
eg: myName =
{$variable}``
LOCAL STORAGE : -
localStorage.setItem("names", "MY LOVE")
console.log(localStorage.getItem("names"))
localStorage.clear()
To convert it to string and to convert it to js object.
`
myLeads = JSON.parse(myLeads)
myLeads.push("ajith")
console.log(myLeads)
myLeads = JSON.stringify(myLeads)
console.log(typeof myLeads)
`
Falsy value JS:
false
0
""
null = how we as a developer signalizes emptiness
undefined = how js signalizes emptiness
NaN
In JavaScript, undefined is a type, whereas null an object. In undefined a variable declared, but no value has been assigned. Whereas, null in JavaScript is an assignment value. You can assign it to a variable.
Top comments (0)